Linux grep – A quick tutorial showing how to use grep to count strings in a text file

Video is ready, Click Here to View ×

In today’s screen cast, I am going to show you how to use the Linux grep command, to quickly count the number of instances of a text string, found within a given file.

The example will demonstrate how to quickly process a web servers access log file, for certain activity. Last month I released the TIFF splitter utility, which is a free piece of software to split multi page TIFF files into their individual
pages. It’s worth pointing out that this software will…


  1. Thanks a lot !
    I'm looking forword also to see the video about the usage of "awk" . I know it's very powful to deal with the text.
    Thanks again for your video and detailed description which really needs a lot of work.

  2. Good video.
    In your example you used : grep *.zip < acess.log , but I usually use it without <
    which is : grep *.zip access.log

    I want to know how to display duplicate lines based on column 2 in a file


    expected output is :

  3. I seam to remember that MS word files are a proprietary binary format, so grep won't be able to search for the plain text within them.

    If you have the AbiWord word processor installed on your machine (or install it via your package manager) then you can use the following command line to convert the contents of the MS Word files to text files.

    find *.doc exec abiword –to=txt -o {}.txt {} ;

    Then you can use grep on the resulting .txt files to find the matches your looking for.

  4. i liked the british female voice, it was refreshing to hear clear speech with prodessional sound quality–good mixing!!! usually the sound recording is amateur at best, i prefer this over a cheap mic with un-processed sound.

    Paul don't change a thing, you're presentation is very good the way it is…please keep it up and please make more…!

  5. If you've watched any of the other tutorials on this topic on the YousTubes, you might understand why I completely appreciate hearing a serious, clear and professional tone of voice for once…this was kind of refreshing to me

  6. @daeheadshot

    Helge sorry you found the voice annoying, I certainly wasn't try to annoy anyone — I was trying to make the video "work safe" and sound professional, but I'll take your comments on board, and try to make future videos less serious


  7. @ritika8sharma2

    Thanks, glad you liked the video.

    You can search all files and sub-folders by doing :-
    grep -rl "stringtofind" .

    Which will list the file names the string to find is found in,
    the dot at the end tells grep to use the current folder as the
    starting point.

    To search for multiple strings use the following format :-

    grep -rl 'string1|string2|string3' .


Leave a Reply

Your email address will not be published.