Benou
October 31, 2011, 8:09am
1
Hello everybody,
I have been looking around but can't figure how to do a grep command, that find the text between multiple patterns, example:
(pattern1 OR pattern2) AND (pattern3 OR pattern4) text that I want (pattern5 OR pattern6) AND (pattern7 OR pattern8)
So how do I find the "text that I want" between <h (and hex equivalent) and i> (and hex equivalent)?
(<|(%3C))*(h|(%68)) text that I want (i|(%49))*(>|(%3E))
Please give me a grep command.
Thanks so much !
Ben
zaxxon
October 31, 2011, 8:17am
2
Can try this one:
sed 's/.*) \([^)(]\+\) (.*/\1/' infile
try this it worked for me...
Benou
October 31, 2011, 8:45am
4
Thanks both of you for the quick reply.
However, I do think that sed is the way to go rather than awk.
Would I be able to introduce a OR in sed?
sed -n '/(<|(%3C))(h|(%68))/,/(i|(%49))(>|(%3E))/p' /path/to/file
Would it be possible to do something like that?
Many thanks!
zaxxon
October 31, 2011, 9:26am
5
You did not say if the provided code worked.
A comma between two patterns defines a range and would print out the lines from pattern 1 to pattern 2. This is no OR.
OR (not explicit):
$> echo xaaax| sed '/\(aaa\|bbb\)/!d'
xaaax
$> echo xbbbx| sed '/\(aaa\|bbb\)/!d'
xbbbx
$> echo xaaabbbx| sed '/\(aaa\|bbb\)/!d'
xaaabbbx