AWK 是一种编程语言,设计用于处理文件或数据流中基于文本的数据,或者使用 shell 管道。 可以将 awk 与 shell 脚本结合使用或直接在 shell 提示符下使用。

建立一个文档 csvtest.csv。
文档内容为:
one, two, three
awk -F, '{print $1}' csvtest.csv
输出为:one
echo "Just get this word: Hello" | awk '{print $5}'
echo "Just get this word: Hello" | awk -F: '{print $2}' | cut -c2-
echo "Just get this word: Hello" | awk -F: '{print $2}' | cut -c2
Sed 主要用来自动编辑一个或多个文件、简化对文件的反复操作、编写转换程序等。
在sedtest.txt文本中,输入文件内容:
The fly flies like no fly flies.
A fly is an insect that has wings and a fly likes to eat leftovers.
在指令行:
sed 's/fly/grasshopper/g' sedtest.txt
输出为:
The grasshopper flies like no grasshopper flies.
A grasshopper is an insect that has wings and a grasshopper likes to eat leftovers.
sed -i.ORIGINAL 's/fly/grasshopper/g' sedtest.txt
所以现在有两个文件:
① sedtest.txt.ORIGINAL
The fly flies like no fly flies.
A fly is an insect that has wings and a fly likes to eat leftovers.
② sedtest.txt
The grasshopper flies like no grasshopper flies.
A grasshopper is an insect that has wings and a grasshopper likes to eat leftovers.