PDA

View Full Version : parsing file in bash (Solaris)



qmqmqm
September 20th, 2010, 10:42 PM
Hi

I have an xml file that contains the following content:

<abc>whatever</abc>
<id>123</id>
<def>something</def>
… …

In bash, how may I get the id number (i.e. "123") out of such a file?

Thanks a lot.

Tom

kurum!
September 21st, 2010, 01:41 AM
perl -ne 'print $1 if m/<id>(.*?)<\/id>/' file

qmqmqm
September 21st, 2010, 05:20 PM
Thanks so much kurum!

Works like a charm.

Tom