使用sed打印文件的第x行到第y行,练习:
生成一个20行的练习文件:
seq 20 > test.txt
文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
打印第11行到第15行:
sed -n -e "11,15 p" -e "15 q" test.txt
使用sed打印文件的第x行到第y行,需要用到的知识:
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
p Print the current pattern space.
q [exit-code]
Immediately quit the sed script without processing any more input.
参考文章:
https://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file