Can some explain the meaning of grep . filename, what does the . (dot) means here.?

Actually it removed all the empty lines in my file.
I just want to know how it's working.

migrated from serverfault.com Feb 21 at 22:28

This question came from our site for system and network administrators.


in grep a dot is meant to be a regex so it stands for any character. If you want to grep occurrences of '.' you can use

grep '\.' filename

(or use fgrep which equals grep -F)

fgrep . filename

Note: If there is an empty line containing a space, it will be shown in the output of:

grep . filename

Why it does not match empty lines? Because there is no character in empty line between ^ and $ (start and end of line). Empty lines-only grep is:

grep '^$' filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy