awk学习总结(两) How awk works and awk CMD in a file
测试文件names
Tom Savage 100 Molly Lee 200 John Doe 300
$0 代表file的整行; $1,第一列;$2,第二列......
$ awk '/Tom/{print $0}' names
$ Tom Savage 100
演示样例二:
$ awk '{print $1,$3}' names $ Tom 100 $ Molly 200 $ John 300
The test files employees and awkfile as following:
$ 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
$ cat awkfile /^Mary/{print "Hello Mary!"} {print $1, $2, $3}
$ awk –f awkfile employees Tom Jones 4424 Hello Mary! Mary Adams 5346 Sally Chang 1654 Billy Black 1683
总结:学到两点东西
1、awk匹配和print能够写到文件。通过-f參数调用
2、awk根据匹配的行,以便从上到下
版权声明:本文博客原创文章。博客,未经同意,不得转载。