linuxbashprintingskip

Print a file, skipping the first X lines, in Bash


I have a very long file which I want to print, skipping the first 1,000,000 lines, for example.

I looked into the cat man page, but I did not see any option to do this. I am looking for a command to do this or a simple Bash program.


Solution

  • Use tail. Some examples:

    $ tail file.log
    < Last 10 lines of file.log >
    

    To SKIP the first N lines:

    $ tail -n +<N+1> <filename>
    < filename, excluding first N lines. >
    

    For instance, to skip the first 10 lines:

    $ tail -n +11 file.log
    < file.log, starting at line 11, after skipping the first 10 lines. >
    

    To see the last N lines, omit the "+":

    $ tail -n <N> <filename>
    < last N lines of file. >