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
HWLOC-ASSEMBLER(1)						       hwloc							HWLOC-ASSEMBLER(1)

NAME
hwloc-assembler - Assemble multiple XML topologies SYNOPSIS
hwloc-assembler [options] output.xml [--name <name1>] input1.xml [--name <name2>] input2.xml ... OPTIONS
-n --name <name> Set <name> in the AssemblerName info attribute of the next input topology root to ease identification within the final global topol- ogy. -f --force Ignore errors while reading input files. -v --verbose Verbose messages. DESCRIPTION
hwloc-assembler combines the input XML topologies and exports the resulting global topologies to a new XML file. All inputs are inserting as children of the global root object. Each input topology root is annotated with info attributes before insertion. AssemblerIndex is set to the index within the list of inputs. AssemblerName is set to the name given with --name if any. hwloc-assembler-remote offers a fron- tend for assembling remote nodes topologies without having to manually gather and transfer each of them. EXAMPLES
To assemble two nodes topologies: $ hwloc-assembler output.xml --name host1 host1.xml --name host2 host2.xml RETURN VALUE
Upon successful execution, hwloc-assembler returns 0. hwloc-assembler will return nonzero if any kind of error occurs, such as (but not limited to) failure to parse the command line. SEE ALSO
hwloc(7), lstopo(1), hwloc-assembler-remote(1) 1.4.1 Feb 27, 2012 HWLOC-ASSEMBLER(1)
All times are GMT -4. The time now is 07:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy