Sponsored Content
Top Forums Shell Programming and Scripting Shell script (not Perl) to parse xml with awk Post 302501426 by ctsgnb on Thursday 3rd of March 2011 01:02:33 PM
Old 03-03-2011
Code:
<defaultName>...</defaultName>
<reportSearchPath>...</reportSearchPath>

...
do these 2 lines appear only once in each and every xml files ?

Here is a ksh shot ok maybe it is not optimized very much because doing 2 pass on the xml file but it should still do the work:

Code:
for i in *.csv
do
      d=$(sed '/defaultName>/!d;s/.*\(....-..-..\).\(..:..:..\).*/\1_\2/;s/[-:]//g;q' "${i%.*}_desc.xml")
      sed '/reportSearchPath>/!d;s/.*:tekuid=\([^,]*\),.*@name=\(.\)\(.*\)\2.*/\1 \3/;q' "${i%.*}_desc.xml" | read u n

       echo "mv $i $n_$d_$u.csv"
       echo "mv ${i%.*}_desc.xml $n_$d_$u.xml"
done

Check that the rename command that will be displayed are correct, and if so ,
change
Code:
echo "mv $i $n_$d_$u.csv"
echo "mv ${i%.*}_desc.xml $n_$d_$u.xml"

with
Code:
mv "$i $n_$d_$u.csv"
mv "${i%.*}_desc.xml $n_$d_$u.xml"

and rerun the script

I didn't treat the "moving to folder" part, since i am not sure to get what you want, however, the code can be adjusted quite easily

Last edited by ctsgnb; 03-03-2011 at 03:03 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

2. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies

3. Shell Programming and Scripting

Need AWk To parse XML logs

Hi , I need an Awk script to parse my log file . 2008-04-26 10:00:13,391 INFO Logger - <?xml version="1.0" encoding="UTF-8" standalone="no"?><2dm tmsg... (0 Replies)
Discussion started by: amit1_x
0 Replies

4. Shell Programming and Scripting

regex/shell script to Parse through XML Records

Hi All, I have been working on something that doesn't seem to have a clear regex solution and I just wanted to run it by everyone to see if I could get some insight into the method of solving this problem. I have a flat text file that contains billing records for users, however the records... (5 Replies)
Discussion started by: Jerrad
5 Replies

5. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

6. Shell Programming and Scripting

AWK to Parse XML messages

Hello Guys, Please help with AWK problem. I have XML file which contains a list of messages for subjects. Example of the messages: , message=, message=, message=, message=, message=, message=, message=, message= I want to use AWK to parse these xml messages but I am... (7 Replies)
Discussion started by: James_Owen
7 Replies

7. Shell Programming and Scripting

awk Script to parse a XML tag

I have an XML tag like this: <property name="agent" value="/var/tmp/root/eclipse" /> Is there way using awk that i can get the value from the above tag. So the output should be: /var/tmp/root/eclipse Help will be appreciated. Regards, Adi (6 Replies)
Discussion started by: asirohi
6 Replies

8. Shell Programming and Scripting

Shell or perl script to replace XML text in bulk

Hi, I am looking for assistance over shell or perl (without XML twig module) which replace string in XML file under particular branch..example of code file sample.. Exact requirment : Replace "Su saldo es" in below file with "Your balance" but only in XML branch of Text id=98 and Text Id=12... (7 Replies)
Discussion started by: Ashu_099
7 Replies

9. Shell Programming and Scripting

How to Parse the XML data along with the URL in Shell Script?

Hi, Can anybody help to solve this. I want to parse some xmldata along with the URL in the Shell. I'm calling the URL via the curl command Given below is my shell script file export... (7 Replies)
Discussion started by: Megala
7 Replies

10. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies
PACEMAKER(8)						  System Administration Utilities					      PACEMAKER(8)

NAME
Pacemaker - Part of the Pacemaker cluster resource manager SYNOPSIS
crm_diff original_xml operation [options] DESCRIPTION
crm_diff - A utility for comparing Pacemaker configurations (XML format) The tool produces a custom (diff-like) output which it can also apply like a patch OPTIONS
-?, --help This text -$, --version Version information -V, --verbose Increase debug output Original XML: -o, --original=value XML is contained in the named file -O, --original-string=value XML is contained in the supplied string Operation: -n, --new=value Compare the original XML to the contents of the named file -N, --new-string=value Compare the original XML to the contents of the supplied string -p, --patch=value Patch the original XML with the contents of the named file Additional Options: -c, --cib Compare/patch the inputs as a CIB (includes versions details) -f, --filter Suppress irrelevant differences between the two inputs EXAMPLES
Obtain the two different configuration files by running cibadmin on the two cluster setups to compare: # cibadmin --query > cib-old.xml # cibadmin --query > cib-new.xml Calculate and save the difference between the two files: # crm_diff --original cib-old.xml --new cib-new.xml > patch.xml Apply the patch to the original file: # crm_diff --original cib-old.xml --patch patch.xml > updated.xml Apply the patch to the running cluster: # cibadmin --patch patch.xml AUTHOR
Written by Andrew Beekhof REPORTING BUGS
Report bugs to pacemaker@oss.clusterlabs.org Pacemaker 1.1.7 April 2012 PACEMAKER(8)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy