【发布时间】:2019-05-06 14:36:12
【问题描述】:
我正在尝试打印只有一个 t 或只有一个 T 的行,其他都可以。 IE没有没有t的行,没有2个或更多t的行,没有1个T和1个t的行。
我正在尝试:
egrep '[tT]{1,1}$' filename
这显示了以下几行:
nopqrstuvwxyz
letters (this line is the one that should not be here)
The price is *$2*
one two three (this line should not be here either)
ONE TWO
THREE
这些是文件中所有带有 t 或 T 的行。我该怎么办?
【问题讨论】:
-
您的尝试不会产生您声称的输出。您的正则表达式在行尾查找 t。 (切线,指定任何东西的重复是完全多余的;您的正则表达式可以简化为
[Tt]$。)
标签: linux bash shell scripting grep