unix - head AND tail of file

前端 未结 20 1275
误落风尘
误落风尘 2020-12-07 11:05

Say you have a txt file, what is the command to view the top 10 lines and bottom 10 lines of file simultaneously?

i.e. if the file is 200 lines long, then view lines

20条回答
  •  星月不相逢
    2020-12-07 11:40

    Building on what @Samus_ explained here about how @Aleksandra Zalcman's command works, this variation is handy when you can't quickly spot where the tail begins without counting lines.

    { head; echo "####################\n...\n####################"; tail; } < file.txt
    

    Or if you start working with something other than 20 lines, a line count might even help.

    { head -n 18; tail -n 14; } < file.txt | cat -n
    

提交回复
热议问题