count matches on the command-line
October 15th, 2007 by Lawrence David
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
October 15th, 2007 by Lawrence David
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
Brilliant idea!
Why not just use grep -c ‘sub_str’ text_file?