|
egrep with multiple regex conditions
Hi,
I am trying to write a bash script that reads through a lot of xml like files and tries to extract certain values.
I am currently stuck trying to pipe the output from the files through egrep where I have three regex conditions that I would like to check for.
For example I want egrep to output the following values if encountered
<OTDataID>15364515
<OTName>IMG_2350.JPG
<OTDataSize>1200026
The three regex conditions
regexp1='<OTDataID>'[0-9]*
regexp2='<OTName>'.*
regexp3='<OTDataSize>'[0-9]*
For some reason no matter how I try to fomulate multiple conditions in egrep it fails with an error or does not return anything.
This works
egrep $regexp1
This fails as it interprets the "|" as a pipe
egrep $regexp1|$regexp2|$regexp3
These do not return anything
egrep -e '($regexp1|$regexp2|$regexp3)'
egrep -E '($regexp1|$regexp2|$regexp3)'
And neither does this
egrep {$regexp1,$regexp2,$regexp2}
returns:
egrep: <OTName>.*: No such file or directory
egrep: <OTName>.*: No such file or directory
This does not return anything:
egrep -E '{$regexp1,$regexp2,$regexp2}'
Any help would be greatly appreciated.
|