How To Filter Blank Lines With GREP

Published Date Author: , Posted May 23rd, 2010 at 5:12:53pm

# filter blank lines
grep -hv "^$" *

# filter blank lines and comments
grep -hv ‘^#’ * | grep -hv "^$"

# filter blank lines, and comments, then count number of lines
grep -hv ‘^#’ * | grep -hv "^$" | wc -l

Note – using FreeBSD’s version of grep. The “-h” argument tells grep to NOT print file names at the beginning of the line. The “-v” says to SKIP matched lines.

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.