User Tools

Site Tools


number_of_matches_per_file

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
number_of_matches_per_file [2021/10/31 21:13] – [Task] adminnumber_of_matches_per_file [2021/11/04 14:59] (current) – [Solution using grep and awk] admin
Line 64: Line 64:
  
 ==== References ==== ==== References ====
-  * https://stackoverflow.com/questions/39945363/frequency-count-for-file-column-in-bash - frequency counting using awk+  * https://stackoverflow.com/questions/39945363/frequency-count-for-file-column-in-bash - count frequencies using awk
  
 ==== tags ==== ==== tags ====
Line 71: Line 71:
 ===== Solution using grep and awk ===== ===== Solution using grep and awk =====
 <code> <code>
-grep -ro "came across" * | awk -F':' '{freq[$1]++} END{for (file in freq) print file ":" freq[file]}'+grep -ro foo * | awk -F':' '{freq[$1]++} END{for (file in freq) print file ":" freq[file]}'
 </code> </code>
  
Line 104: Line 104:
 </code> </code>
  
-Note: You have to use "grep -o" instead of "grep -c". If a string occurs multiple times in a line, "grep -o" matches each of them separately. But "grep -c" counts them together. For example+Note: You have to use "grep -o" and not "grep -c". If a string occurs multiple times in a line, "grep -o" matches each of them separately. But "grep -c" counts them together. For example
  
 <code> <code>
number_of_matches_per_file.1635714830.txt.gz · Last modified: 2021/10/31 21:13 by admin