I need to count the lines from matching config file entries, preferably with 'grep'.

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-05-12T14:32:58Z Indexed on 2010/05/12 14:34 UTC
Read the original article Hit count: 177

Filed under:
|
|

I have a configuration file that has entries for various devices, with each entry separated by a blank line. I need to search the file for all instances of a given device type, and count the number of non-blank lines following the occurrence, stopping at the first blank.

For example:

Server=foo
config line 1
config line 2
config line 3

Server=bar
config line 1
config line 2

Server=foo
config line 1

If I wanted to know how many total "config lines" were associated with server "foo", I should get four. Can you please help?

© Stack Overflow or respective owner

Related posts about grep

Related posts about count