user983223
user983223

Reputation: 1154

regex of string

I want to put the value of percentComplete in the jobStatus in a variable to use later in a shell script. This data goes into a txt file and continually prints these two paragraphs updating the data. I want to be able to get the percentComplete. I have cat the txt file but I don't know the regular expression to use to get the percentComplete (the one inside the jobStatus).

<batchStatus name="" submissionTime="1/23/12 10:00:26 AM" sentBy="mike" 
timeElapsed="43 second(s)" timeRemaining="4 minute(s)" timeElapsedSeconds="43"
timeRemainingSeconds="294" percentComplete="12" resumePercentComplete="0" 
status="Processing" batchid="FD66DC21-6AA4-47FB-A3F0-7300C7BDAB8A" /batchStatus>
<jobStatus name="file.mov" submissionTime="1/23/12 10:00:26 AM" sentBy="mike"
 jobType="Compressor" priority="HighPriority" timeElapsed="43 second(s)" 
timeRemaining="4 minute(s)" timeElapsedSeconds="43" timeRemainingSeconds="294"
 percentComplete="12" resumePercentComplete="0" status="Processing: Transcoding" 
jobid="FDF1A488-51B9-4B9A-908B-FD5D95CE7E92" 
batchid="FD66DC21-6AA4-47FB-A3F0-7300C7BDAB8A" /jobStatus>

Upvotes: 0

Views: 96

Answers (2)

unwind
unwind

Reputation: 399813

It's a bad idea to parse XML using regular expressions. Regular expressions are not powerful enough, since XML is not a regular language.

Upvotes: 1

dorsh
dorsh

Reputation: 24700

It's a very bad idea to use regex for this, you'd be much happier using an XML parser.

If you still want to:

<jobStatus[^>]*percentComplete="([\d]+)"

Upvotes: 1

Related Questions