Reputation: 155
I have written perl script for parsing input text/file as follow:
[root@agent tmp]# head ./test_regqexp_keynote.txt
[email protected] (Top20) Carnation GB/fd (Crit) 9:57 11 KB
[email protected] (Shell Brand EUR) HealthScience NL/fd (Crit) 9:36
11 KB
[email protected] (Shell Corp AMS) Nestle JP/fd (Crit) 9:16 11 KB
[email protected] (Top20) NestleHealth DE/fd (Crit) 9:01 11 KB
[email protected] (Shell Corp AMS) Nestle NZ/fd (Crit) 8:17 12 KB
[email protected] (Shell Brand EUR) HealthScience CH/fd (Crit) 8:11
11 KB
[email protected] (Shell Corp AMS) Nestle CL/fd (Crit) 8:11 11 KB
[email protected] (Shell Corp AMS) Nestle VE/fd (Crit) 8:11 11 KB
and getting text as follow on output:
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";}'
So just extract of part "XXXX XX/fd".
But I need it to be done using SED tool.
And it made me crazy. Seems that SED works in totally different way or has very different rules of RegEx.
Please help me to convert this RegExp query to SED RegExp query. Or explain what is mainly different in Sed RegExp from Perl or Egrep RegExp.
Upvotes: 0
Views: 84
Reputation: 41456
Instead of complicated regex, you can try this awk
awk -F"[)] | [(]" 'NF>3{print $3}' file
Carnation GB/fd
HealthScience NL/fd
Nestle JP/fd
NestleHealth DE/fd
Nestle NZ/fd
HealthScience CH/fd
Nestle CL/fd
Nestle VE/fd
Upvotes: 0
Reputation: 333
sed -n 's#.* \([a-zA-Z]* [A-Z]\{2,3\}/fd\).*#\1#p' test_regqexp_keynote.txt
Or:
egrep -o '[a-zA-Z]* [A-Z]{2,3}/fd' test_regqexp_keynote.txt
Upvotes: 0
Reputation: 97948
Here is one way:
sed -n 's!.* \([a-zA-Z]* [A-Z]\{2,3\}/fd\).*!\1!p' input
and perhaps this may work too:
sed -n 's!.* \([^ ]* [^ ]*/fd\).*!\1!p' input
Upvotes: 1