1、cut:字段截取
[root@master regex]# cat stu.txt
ID Name gender Mark
1 Jordan M 100
2 Kobi M 99
3 Mom F 90
[root@master regex]# cut -f 2 stu.txt
Name
Jordan
Kobi
Mom
[root@master regex]# cut -f 2,3 stu.txt
Name gender
Jordan M
Kobi M
Mom F
2、printf:字符输出函数
[root@master regex]# printf '%s\t%s\t%s\t%s\n' $(cat stu.txt)
ID Name gender Mark
1 Jordan M 100
2 Kobi M 99
3 Mom F 90
3、awk:处理文本文件
[root@master regex]# awk '{printf $2 "\t" $4 "\n"}' stu.txt
Name Mark
Jordan 100
Kobi 99
Mom 90
[root@master regex]# awk '{print $2 "\t" $4 "\n"}' stu.txt
Name Mark
Jordan 100
Kobi 99
Mom 90
[root@master regex]# awk '{print $2 "\t" $4}' stu.txt
Name Mark
Jordan 100
Kobi 99
Mom 90
[root@master regex]# awk 'BEGIN{print "test"}{print $2 "\t" $4}' stu.txt
test
Name Mark
Jordan 100
Kobi 99
Mom 90
[root@master regex]# awk 'END{print "test"}{print $2 "\t" $4}' stu.txt
Name Mark
Jordan 100
Kobi 99
Mom 90
test
[root@master regex]# cat /etc/passwd|grep /bin/bash
root:x:0:0:root:/root:/bin/bash
keyan:x:1000:1000:keyan:/home/keyan:/bin/bash
kudu:x:987:981:Kudu:/var/lib/kudu:/bin/bash
[root@master regex]# cat /etc/passwd|grep /bin/bash| awk '{FS=":"}{print $1 "\t" $3}'
root:x:0:0:root:/root:/bin/bash
keyan 1000
kudu 987
[root@master regex]# cat /etc/passwd|grep /bin/bash| awk 'BEGIN{FS=":"}{print $1 "\t" $3}'
root 0
keyan 1000
kudu 987