1. 程式人生 > >linux 如何顯示一個文件的某幾行(中間幾行)

linux 如何顯示一個文件的某幾行(中間幾行)

如何 sed命令 gpo sed linux cat file head pos

【一】從第3000行開始,顯示1000行。即顯示3000~3999行

cat filename | tail -n +3000 | head -n 1000

【二】顯示1000行到3000行

cat filename| head -n 3000 | tail -n +1000

*註意兩種方法的順序

分解:

tail -n 1000:顯示最後1000行

tail -n +1000:從1000行開始顯示,顯示1000行以後的

head -n 1000:顯示前面1000行

【三】用sed命令

sed -n ‘5,10p‘ filename 這樣你就可以只查看文件的第5行到第10行。

linux 如何顯示一個文件的某幾行(中間幾行)