Useful bash commands

Remove the last 1 line of output:

printf "1\n2\n3\n4\n5\n" | head -n-1
1
2
3
4

without ” | head -n-1″, the printf command yeilds:

printf "1\n2\n3\n4\n5\n"
1
2
3
4
5

Remove the first 1 line of output:

printf "1\n2\n3\n4\n5\n" | tail -n+2
2
3
4
5

You can change the number in any command you like. tail -n+1 doesn’t seem to remove any lines, so add 1 to whatever number of lines you want to remove.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.