![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Authorizing Access to Dynamic Spatial-Temporal Data | iBot | Oracle Updates (RSS) | 0 | 04-18-2008 03:10 PM |
| parsing data file picking out certain fields | timj123 | Shell Programming and Scripting | 8 | 03-05-2008 03:57 PM |
| Parsing and getting data from XML file using ksh script | vinna | Shell Programming and Scripting | 6 | 12-08-2007 10:10 AM |
| Parsing the data in a file | Omkumar | Shell Programming and Scripting | 2 | 05-20-2005 05:59 AM |
| search and replace dynamic data in a shell script | csejl | Shell Programming and Scripting | 8 | 10-21-2003 07:33 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now:
echo -n "Running data test... " cat datafile.xml | sed -e s/changethis/intothis/ > /tmp/$$.xml export RESULT=`~/xml /tmp/$$.xml | grep "<Code>SUCCESS</Code>"` if [ "$RESULT" != "" ]; then { echo passed } else { echo FAILED ; exit } fi The XML file has the data I need stored between XML tags, so I know I could grep that line and output it to another file, and use that file to refer to for the input in the next test. That file would have < Number >here'sthedata< /Number > in that file. The trick would be to parse the data out, in effect removing the tags, storing that value in a variable, and then using sed to do a replace in the new input file like I am above. I'm just unsure how to go about parsing the data out. Hope this wasn't confusing Last edited by corwin43; 11-01-2001 at 01:02 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Well... if you don't mind going to Perl, (I would recommend this)
you can use the XML::Parser Perl module... http://wwwx.netheaven.com/~coopercc/...ser/intro.html ...it would be alot more flexable and in the long run, I think you'll need that anyway. |
|
#3
|
|||
|
|||
|
(bash bash bash) |
|
#4
|
||||
|
||||
|
PERL is really not so difficult to learn and there must be hundreds of samples on the net for how to build PERL::XML transformations:
PERL XML FAQ XMLperl And so much more: Google search |
|
#5
|
||||
|
||||
|
If you REALLY, REALLY want to use awk, I guess you can
do somthing like... Code:
#!/bin/sh
awk '/<Number>/ {stp=index($0,">")+1; \
newstr=substr($0,stp); \
etp=index(newstr,"<")-1; \
print substr(newstr,0,etp); \
}' test.xml
Code:
<String>one</String> <Number>two</Number> <String>three</String> <Number>four</Number> "<Number>" lines only. I hope this encourages you to look at Perl again. |
|
#6
|
||||
|
||||
|
Damn...
The XML strings disappeard in the previous post... Note I changed all the angle brackets "<" to square brackets "[". you'll have to translate them back. script... #!/bin/sh awk '/[Number]/ {stp=index($0,">")+1; \ newstr=substr($0,stp); \ etp=index(newstr,"<")-1; \ print substr(newstr,0,etp); \ }' test.xml test.xml [String]one[/String] [Number]two[/Number] [String]three[/String] [Number]four[/Number] |
||||
| Google The UNIX and Linux Forums |