How do i count the number of matching lines using grep?



  • Man page for grep: https://www.lightnetics.com/post/3317

    The contents of the file is:

    $ cat grepfile
    grapes
    apples
    pears
    This is the first block
    oranges
    plums
    
    grapes
    apples
    pears
    This is the second block
    oranges
    plums
    
    grapes
    apples
    pears
    This is the third block
    oranges
    plums
    

    Three lines have the matching string block.

    $ grep -c block grepfile
    3
    


© Lightnetics 2024