输出特定的行与列

Zss 发表于:

1.显示用grep来过滤一下br字符   ifconfig | grep br

admin@C2s-252:~$ ifconfig | grep br
br-chi0 Link encap:Ethernet HWaddr 02:19:BE:29:01:FE
br-chi1 Link encap:Ethernet HWaddr 02:19:BE:29:01:FF
br-lan Link encap:Ethernet HWaddr 00:19:BE:29:01:FC
br-lan:1 Link encap:Ethernet HWaddr 00:19:BE:29:01:FC
br-lan:2 Link encap:Ethernet HWaddr 00:19:BE:29:01:FC
br-nginx Link encap:Ethernet HWaddr 4A:97:B9:96:31:AD

 

2.输出第三行,awk ‘NR==3{print}’

admin@C2s-252:~$ ifconfig | grep br|awk ’NR==3{print}’
br-lan Link encap:Ethernet HWaddr 00:19:BE:29:01:FC

 

3.输出第三行和第五行

seq 10|awk ‘NR==3{print}’;seq 10|awk ‘NR==5{print}’

 

4.输出第三行到第五行

seq 10|awk ‘NR>=3 && NR<=5{print}’

seq 10|sed -n ‘5,7p’

5.输出第三行到第五行的第二列

seq 10|awk ‘NR>=3 &&NR<=5{print $2}’