Skip to main content

Timeline for Count lines containing word

Current License: CC BY-SA 4.0

7 events
when toggle format what by license comment
Jan 5, 2019 at 10:17 comment added Larry @matja: I actually made the answer you provided before the current one. However, it does not do what OP asked for. I misread the question at first entirely as well, and was corrected by glenn jackman. What you are suggesting would count every occurrence of each word. What OP asked for is to count the number of lines each word occurs in at least once.
Jan 5, 2019 at 10:11 comment added matja vikarjramun@ no, but uniq -c gives you the counts of each word in one pass, so you don't have to use xargs to do multiple passes of the input file for each word.
Jan 5, 2019 at 3:31 comment added vikarjramun @matja is sort | uniq -c more efficient than sort -u?
Jan 5, 2019 at 0:14 comment added matja An optimisation to this approach: fmt -1 words.txt | sort | uniq -c | awk '{ print $2 ":" $1 }'
S Jan 4, 2019 at 21:13 history suggested vikarjramun CC BY-SA 4.0
Added a more in-depth explanation of what the command does.
Jan 4, 2019 at 20:12 review Suggested edits
S Jan 4, 2019 at 21:13
Jan 4, 2019 at 17:33 history answered Larry CC BY-SA 4.0