I need help for some command for handle the following situation.
I search on net for help but i can’t succeed to find solution.
Problem is:
I have a xml file named as “temp.xml”
The text in the xml file is for example
<?xml version="1.0" encoding="utf-8"?>
<NoteData Note_Nbr="312" Data_Revision="2" Note_Revision="1" />
I want to save only Note_Nbr to my variable x (312)
I try a something but it doesn’t work.
X=$(sed -r 's/[^|]*(Note_Nbr=")(\d\d\d)([^|]*)/2 /' temp.xml )
Thank you for your helps.
The right way to do this is with a real XML parser:
…or, if you have XMLStarlet rather than a new enough xmllint:
See also this answer: https://stackoverflow.com/a/1732454/14122
Now, if you only wanted to work with literal strings, you could build something fragile that looked like this, using parameter expansion:
Alternately, you could use native regular expression support within bash (note that this functionality is a bash extension not present in POSIX sh):