在Bash中重复字母的单词

时间:2014-09-26 17:24:33

标签: regex linux bash command-line

egrep \e '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z){2,}' dict.txt

我做错了什么?字典单词都是小写字母。

如果{}不支持区间功能egrep,我应该使用哪个命令?

2 个答案:

答案 0 :(得分:4)

你可以这样做,

egrep -e '([a-z])\1+' file

示例:

$ cat file
bbar 
fooohsg
jhfd
$ egrep -e '([a-z])\1+' file
bbar 
fooohsg

答案 1 :(得分:1)

你需要逃避{}

grep '\([a-z]\)\1\{1,\}' dict.txt将匹配任意数量的重复

$ echo "aab" | grep '\([a-z]\)\1\{1,\}'
aab
相关问题