我正在尝试使用 grep 查找以重复字母字符 (a-zA-z) 开头的行。完成此操作的正确 grep 命令是什么?
这是我到目前为止所拥有的:
grep -E '[:alpha:]' $lines1
答案1
这似乎是您寻求的表达:
^([A-Za-z])\1
如图所示:
$ grep -E '^([A-Za-z])\1' input
aardvark
$ grep -E '^([[:alpha:]])\1' input
aardvark
$ cat input
apple
aardvark
bookkeeper
扩展表达式:
NODE EXPLANATION
^ the beginning of the string
( group and capture to \1:
[A-Za-z] any character of: 'A' to 'Z', 'a' to 'z'
) end of \1
\1 what was matched by capture \1