unix - head AND tail of file

前端 未结 20 1214
误落风尘
误落风尘 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:38

    First 10 lines of file.ext, then its last 10 lines:

    cat file.ext | head -10 && cat file.ext | tail -10

    Last 10 lines of the file, then the first 10:

    cat file.ext | tail -10 && cat file.ext | head -10

    You can then pipe the output elsewhere too:

    (cat file.ext | head -10 && cat file.ext | tail -10 ) | your_program

提交回复
热议问题