awk ——awk将每个输入行解释为一条记录而将一行上的每个单词(由空格或行由制表符分隔)解释为每个字段。
# space.txt
root@357c42f4740c:/test# cat space.txt
hello world c
hello world c++
hello world python
hello world go
hello world java
$0代表输入的整行记录。
root@357c42f4740c:/test# awk ' /[c*]/ { print $0 }' space.txt
hello world c
hello world c++
$1代表每行第一个字段
root@357c42f4740c:/test# awk ' /[c*]/ { print $1 }' space.txt
hello
hello
-F选项+自定义分隔符,重新定义分隔符。
hello.world.c
hello.world.c++
hello.world.python
hello.world.go
hello.world.java
root@357c42f4740c:/test# awk -F. ' /c/ { print $3 }' space.txt
c
c++