【发布时间】:2014-05-30 16:42:34
【问题描述】:
我已经编写了用于解析输入文本/文件的 perl 脚本,如下所示:
[root@agent tmp]# head ./test_regqexp_keynote.txt
alert@keynote.com (Top20) Carnation GB/fd (Crit) 9:57 11 KB
alert@keynote.com (Shell Brand EUR) HealthScience NL/fd (Crit) 9:36
11 KB
alert@keynote.com (Shell Corp AMS) Nestle JP/fd (Crit) 9:16 11 KB
alert@keynote.com (Top20) NestleHealth DE/fd (Crit) 9:01 11 KB
alert@keynote.com (Shell Corp AMS) Nestle NZ/fd (Crit) 8:17 12 KB
alert@keynote.com (Shell Brand EUR) HealthScience CH/fd (Crit) 8:11
11 KB
alert@keynote.com (Shell Corp AMS) Nestle CL/fd (Crit) 8:11 11 KB
alert@keynote.com (Shell Corp AMS) Nestle VE/fd (Crit) 8:11 11 KB
并在输出中获取如下文本:
HealthScience FI/fd
DolceGusto NZ/fd
Waters WW/fd
Nestle UA/fd
Nestle SK/fd
Nestle SI/fd
perl -ne 'if ($_=~ m/([a-zA-Z]* [A-Z]{2,3}\/fd)/) {print "$1\n";}'
所以只是“XXXX XX/fd”部分的摘录。
但我需要使用 SED 工具来完成。
这让我发疯了。似乎 SED 以完全不同的方式工作或具有非常不同的 RegEx 规则。
请帮我将此 RegExp 查询转换为 SED RegExp 查询。或者解释一下 Sed RegExp 与 Perl 或 Egrep RegExp 的主要区别。
【问题讨论】:
-
谢谢大家!很棒且有用的答案。