AWK 记录和域
The NR Variable
% awk ‘{print NR, $0}‘ employees 1 Tom Jones 4424 5/12/66 543354 2 Mary Adams 5346 11/4/63 28765 3 Sally Chang 1654 7/22/54 650000 4 Billy Black 1683 9/23/44 336500
NR 加入行号。逐行加一
$0 代表整行
NF 文件列数
% awk ‘{print $0, NF}‘ employees Tom Jones 4444 5/12/66 543354 5 Mary Adams 5346 11/4/63 28765 5 Sally Chang 1654 7/22/54 650000 5 Billy Black 1683 9/23/44 336500 5
-F
% cat employees Tom Jones:4424:5/12/66:543354 Mary Adams:5346:11/4/63:28765 Sally Chang:1654:7/22/54:650000 Billy Black:1683:9/23/44:336500 % awk –F: ‘/Tom Jones/{print $1, $2}‘ employees2 Tom Jones 4424
eg2
% awk –F‘[ :\t]‘ ‘{print $1, $2, $3}‘ employees Tom Jones 4424 Mary Adams 5346 Sally Chang 1654 Billy Black 1683
总结:学习了NR NF 变量 学会使用-F參数
时间: 2024-10-15 14:03:13