Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想找到我尝试过的 aaa、bbb 等:
grep -E [a-z]\{3\} 1.txt
但这甚至打印 abc
您可以使用对捕获组的引用:
[/tmp] cat test.txt aaa bbb abc aab bbc [/tmp] grep -E "([a-z])\1{2}" test.txt aaa bbb
\1指的是([a-z])(在您的情况下为单个字母)捕获的内容,因此正则表达式会查找单个字母,然后再查找相同的字母两次。
\1
([a-z])
另一种变体:
grep '\([a-z]\) *\1\1' fileName