Search code examples
bashsedawkheadtail

Omit lines from the beginning or end of a file in Bash


Given a text file a.txt, how to cut the head or tail from the file?

For example, remove the first 10 lines or the last 10 lines.


Solution

  • to list all but the last 10 lines of a file:

    head -n -10 file
    

    to list all but the first 10 lines of a file:

    tail -n +10 file