Thursday, December 27, 2012

Extract String Value from XML attribute in a text file

I have an xml which is similar to below in a file called filename.txt

<tag1 attribute1="1234"></tag1>
<tag1 attribute1="4567"></tag1>

I need to extract the values of the attributes alone into another text file.
To do this in unix, a combination of grep and sed works as below:

grep "attribute1=" filename.txt|sed 's/.*attribute1="\([0-9]*\).*/\1/'   > valuelist.list

This will write the list of values to valuelist.list

0 Comments:

Post a Comment

<< Home