5

I need a grep command that finds all lines that only contain words with lengths greater than 10.

this is the grep I wrote to find words bigger than 10 characters.

grep -E '(\w{11,})' input

How would I manipulate this command to include every word on the line?

2
  • 1
    Dear Mike, please consider accepting the answer which solved your question by clicking ✔sign next to the answer. thank you Nov 3, 2017 at 6:29
  • yes mike, please :) The answer is a good one even after 5 years @αғsнιη (though mike is last seen 4 years ago :( )
    – WoJ
    Mar 8, 2022 at 15:34

1 Answer 1

9

Your condition might be more easily expressed in the contrapositive: instead of including lines where all words have length > 10, exclude those lines which have a word with length <= 10. Since grep supports both negation and word-matching, this could be written as, say:

grep -vwE '\w{1,10}'
  • -v negates the match
  • -w means that the regex should match a whole word

As Sundeep noted, we should use {1,10} to avoid matching the empty string (and thus every line).

1
  • 1
    use {1,10} ... see the output for echo 'fooo bar ;' | grep -vwE '\w{,2}' and echo 'fooo bar ;' | grep -vwE '\w{1,2}'
    – Sundeep
    Nov 3, 2017 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .