Feed on
Posts
Comments

to count the number of times you match a substring in a larger text file, you can use the following shell one-liner:

>> sed “s/[sub_str]/[sub_str]\n/g” [text_file] | wc -l


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “count matches on the command-line”

  1. on 23 Feb 2012 at 6:10 am zoltanctoth

    Brilliant idea! :)

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.