Bash: grep: A couple of usefull applications


(How) to delete all empty lines from a file:

cat someFile | grep -v '^$'

(How) to get all numbers that have no sign in front of them (all positive numbers, from a file where on each line there is one number only):

cat someFile | grep ^[0-9]

(How) to extract all negative numbers (from a file where on each line there is one number only):
You can of course replace the minus ‘-‘ character with any other you want to use as a starting character for a line.

cat someFile | grep ^-

This post is also available in: Greek

Leave a Reply

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