Reputation: 13
I'm trying to make a batch file to pull data out of a file and set it as a variable.
The tricky part is I need to read a XML file, and I only need the data between the quotes of the following line...
narrative="I only need this text here"
The text in that line can also contain spaces, brackets, slashes, dashes and colons.
SAMPLE XML FILE :
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<cadcall>
<call callnumber="123456" jurisdiction="abcd" department="dept 1" complaint="cost" priority="M" calltencode="" callername="Persons Name" phonenumber="Cell Number HERE" narrative="[10/02/2012 14:56:27 : pos9 : PERSON] Fairly long narrative here describing issue of dispatch, but sometimes these can be short." alarmtype="" ocanumber="0000000000" disposition1="TRAN" />
</cadcall>
Upvotes: 0
Views: 335
Reputation: 185015
The proper tool to do this is xmllint
from libxml
, please, provide a more complete XML example, I will tell you how to use a Xpath
request on your XML
.
EDIT :
here a solution using Xpath (with a little hack : contains
) :
xmllint --xpath '/cadcall/call/@narrative[contains(.,'.')]' file.xml
Upvotes: 1
Reputation: 195039
without seeing the complete input, just based on your example line. grep works for you.
kent$ echo 'narrative="I only need this text here"'|grep -Po '(?<=narrative=")[^"]*'
I only need this text here
Upvotes: 0