Is there a way to find all lines with grep, that contains at least x words?
Tell me more
×
Super User is a question and answer site for
computer enthusiasts and power users. It's 100% free, no registration required.
|
Well, assuming words are separated by spaces, to find lines with >= 5 words, do this:
Grep is not the best tool for the job though, try gawk:
Gawk's NF variable holds the number of fields, by default fields are defined by spaces, so in a line of text each field is a word. The command above will print all lines containing more than 4 words. |
|||||||
|
|
Replace the number "3" if you want lines >= to a different value.
|
|||
|
|