使用head,tail,grep, sed,awk三种方法显示linux中间若干行

需要显示文本中间20-25行.

创建一个30行的文档,命名为30.txt并显示在屏幕

[root@v2-ui data]# seq 30 > 30.txt && cat 30.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@v2-ui data]#
View Code

方法一:

[root@v2-ui data]# head -25 30.txt | tail -6
20
21
22
23
24
25
[root@v2-ui data]# 
View Code

方法二:

[root@v2-ui data]# sed -n "20,25"p 30.txt
20
21
22
23
24
25
[root@v2-ui data]#
View Code

-n表示第XX行,p打印的意思

方法三:

1 [root@v2-ui data]# awk "NR>19 && NR <26" 30.txt 
2 20
3 21
4 22
5 23
6 24
7 25
8 [root@v2-ui data]# 

NR表示行号

猜你喜欢

转载自www.cnblogs.com/homeboot/p/12118302.html