正则awk和查看文件行数

时间:2021-11-02 23:17:56

[root@WebServer aa]# cat oldboy.txt
I am oldboy myqq is 49000448
[root@WebServer aa]# cat oldboy.txt |cut -d " " -f3,6
oldboy 49000448
[root@WebServer aa]# awk '{print $3,$6}' oldboy.txt
oldboy 49000448

多个分隔符

[root@WebServer aa]# cat oldboy.txt
I am oldboy,myqq is 49000448
[root@WebServer aa]# awk -F '[ ,]' '{print $3" "$6}' oldboy.txt
oldboy 49000448

[root@WebServer aa]# cat /etc/services |wc -l
10774

[root@WebServer aa]# cat -n /etc/services |tail -1   查看结果的最后一行
10774 iqobject 48619/udp # iqobject

[root@WebServer aa]# awk '{print NR}' /etc/services |tail -1
10774

[root@WebServer aa]# grep -n $ /etc/services |tail -1
10774:iqobject 48619/udp # iqobject