number_of_matches_per_file
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
number_of_matches_per_file [2021/10/31 18:02] – [Task] admin | number_of_matches_per_file [2021/11/04 14:59] (current) – [Solution using grep and awk] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Task ===== | ===== Task ===== | ||
- | Given a bunch of files in a directory, count the number of times a word occurs in each of the file. For example | + | Given a bunch of files in a directory, count the number of times a word occurs in each file. For example, given |
< | < | ||
Line 18: | Line 18: | ||
</ | </ | ||
- | count the number of times the word ' | + | count the number of occurrences of ' |
< | < | ||
junk1.txt:4 | junk1.txt:4 | ||
Line 64: | Line 64: | ||
==== References ==== | ==== References ==== | ||
- | * https:// | + | * https:// |
==== tags ==== | ==== tags ==== | ||
Line 71: | Line 71: | ||
===== Solution using grep and awk ===== | ===== Solution using grep and awk ===== | ||
< | < | ||
- | grep -ro "came across" | + | grep -ro foo * | awk -F':' |
</ | </ | ||
Line 104: | Line 104: | ||
</ | </ | ||
- | Note: You have to use "grep -o" | + | Note: You have to use "grep -o" |
< | < |
number_of_matches_per_file.txt · Last modified: 2021/11/04 14:59 by admin