Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

May 052012
 

Count the number of lines contain a specific string using grep

Answer:

Usually when you want to count the number of lines contain a specific string, it is easy with the grep command,

e.g.

# cat input.txt | grep foo | wc -l

But actually a more direct approach would be:

# cat input.txt | grep -c foo

  One Response to “Count the number of lines contain a specific string using grep”

  1. Well, actually you only need the grep command:

    grep -c foo input.txt

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>