grep 用于所有单词长度大于 10 个字符的行

mik*_*ike 5 grep text-processing

我需要一个grep命令来查找所有只包含长度大于 10 的单词的行。

这是grep我为了查找大于 10 个字符的单词而写的。

grep -E '(\w{11,})' input
Run Code Online (Sandbox Code Playgroud)

我将如何操作此命令以包含行上的每个单词?

mur*_*uru 8

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}'
Run Code Online (Sandbox Code Playgroud)
  • -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).