6

用awk处理文本

 3 years ago
source link: https://houye.xyz/2018-03/awk/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

awk作为命令行工具

awk是输入驱动的, awk程序由一个现成的主输入循环组成,你可以在这个框架下编写代码。

在shell中运行这行代码,由于没有提供文件名,awk从标准输入读取内容,每读取一行文本,脚本打印一行文字。

awk '{print "a new line"}'

awk也可以从文件读取内容,最后一个参数就是文件名,awk程序会打开它并一行行的读取文件内容。

awk '{print "a new line"} test.txt

除了主输入循环,还有两个特殊的部分――BEGIN和END,分别可以做输入前和输入完成后的处理,这里的输入前和输入后,指的读入任何输入前和所有输入完成后。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK