0

I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:

123

// comment
45

As you can see, there is a line above //comment. If I want to count the times such line exist in my file, how can I grep them?

0

1 Answer 1

4

You can grep empty lines with grep '^$' file and count the lines with wc -l. Combined it's:

grep '^$' file | wc -l

or even shorter with grep's count option -c or --count

grep -c '^$' file
1
  • 1
    grep -cv . file where we reverse the match. Sep 9, 2019 at 4:10

You must log in to answer this question.