Useful Shell Scripting: Skip first n lines of a text

This is one of those really amazing shell commands which is very concise, powerful, and yes elegant.

Let’s say you have a file of some text and want to view everything except the top n lines of file.txt, where n is any number.  The command simply is:

awk 'NR>n' file.txt

Where n is the number of lines at the beginning of file.txt to skip.

You can then do whatever you want with the output, like pipe it to some other command.  By the way, you can also pipe in to awk, i.e. go the other way, as:

some_command file.txt |awk 'NR>n'

So awesome!  And so simple even I can remember it 🙂


Comments

Leave a Reply