2

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?

5

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
    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 '17 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.