xml extract problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting xml extract problem
# 8  
Old 10-02-2011
Try this...

Code:
awk -F">" '/oftware.com\/tomboy\/size/{x=$NF;f=1;next} /note-content/{f=0;print x;x=""} {if(f==1)x=x" "$0;}'  input_file

--ahamed
# 9  
Old 10-02-2011
I did this with awk version and did not get the uninstall after audacity from previous post. I tried it on all my notes and same issue missing entries.
Code:
awk -F">" '/oftware.com\/tomboy\/size/{x=$NF;getline;getline;x=x" "$0;}/note-content/{print x;x=""}' *.note /dev/null >> filedump

---------- Post updated at 02:18 PM ---------- Previous update was at 02:17 PM ----------

ah didn't see previous note before my send. Will try this.

---------- Post updated at 07:21 PM ---------- Previous update was at 03:18 PM ----------
Code:
<?xml version="1.0"?>
#This is one line above. Not in actual file
<note version="0.3"  xmlns:link="http://beatniksoftware.com/tomboy/link"  xmlns:size="http://beatniksoftware.com/tomboy/size"  xmlns="http://beatniksoftware.com/tomboy"><title>A installer au  menu</title><text xml:space="preserve"><note-content  version="0.1" xmlns:link="http://beatniksoftware.com/tomboy/link"  xmlns:size="http://beatniksoftware.com/tomboy/size">To install in  menu
#This is one line above. Not in actual file

#This is one line above. Not in actual file

#This is one line above. Not in actual file
audacity
#This is one line above. Not in actual file

#This is one line above. Not in actual file
uninstsall
#This is one line above. Not in actual file
</note-content>
#This is one line above. Not in actual file

Ok, this line
Code:
/tomboy/size">To install in  menu

is always the ending part of the 3rd line including the title of the note.
After it could be as many lines depending of content and always ending note entries with
Code:
</note-content>

Note though, in some instances there is no carriage return after the last note entry. The command I tried with awk left out the last line if no carriage return!

I am trying to understand the command but, I'm having difficulty understanding some parts.

I'm using Awk - A Tutorial and Introduction - by Bruce Barnett
this site to get to know the functions of the command.

Anyway thanks for your generous help

Last edited by Scott; 10-03-2011 at 11:09 AM.. Reason: Code tags
# 10  
Old 10-03-2011
Try this...
Code:
awk -F"<|>" '/oftware.com\/tomboy\/size/{x=$NF;f=1;next} /note-content/{f=0;print x" "$1;x=""} {if(f==1)x=x" "$0;}' input_file

--ahamed
# 11  
Old 10-03-2011
Yeah, you got it!

Did all the notes and worked like a charm.
I'll still have to look at it closer so I can understand how this thing works. Awk is not easy to learn but with examples like this I should get a grip on it.

Thanks ahamed101
# 12  
Old 10-03-2011
You are welcome Smilie
Good Luck with awk!

--ahamed
# 13  
Old 10-03-2011
awk -F"<|>"
'/oftware.com\/tomboy\/size/{x=$NF;f=1;next}
caught exception oftware/tomboy/size then x= last field -F"<|> field is after one of those


/note-content/{f=0;print x" "$1;x=""}
check if end of content, if yes print first field, if no goto if


{if(f==1)x=x" "$0;}' Not note-content then print whole line
if yes print first field only

Is that right ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a value from an xml file

I have this XML file format and all in one line: Fri Dec 23 00:14:52 2016 Logged Message:689|<?xml version="1.0" encoding="UTF-8"?><PORT_RESPONSE><HEADER><ORIGINATOR>XMG</ORIGINATOR><DESTINAT... (16 Replies)
Discussion started by: mrn6430
16 Replies

2. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

3. Shell Programming and Scripting

Extract a particular xml only from an xml jar file

Hi..need help on how to extract a particular xml file only from an xml jar file... thanks! (2 Replies)
Discussion started by: qwerty000
2 Replies

4. Shell Programming and Scripting

Extract string from XML

Hi, I wish to grep for the first instance of <listen-address> value between the first <server></server> tag in an xml file. Sample xml: ......... <timeout-seconds>1500</timeout-seconds> </jta> <server> <name>Adminserver_DEV</name> ... (9 Replies)
Discussion started by: mohtashims
9 Replies

5. Shell Programming and Scripting

Extract value from XML

I have a file like below <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:executeMDXResponse... (9 Replies)
Discussion started by: manas_ranjan
9 Replies

6. Shell Programming and Scripting

sed extract from xml

I have an xml file that generally looks like this: "<row><dnorpattern>02788920</dnorpattern><description/></row><row><dnorpattern>\+ 44146322XXXX</dnorpattern><description/></row><row><dnorpattern>40XXX</dnorpattern><description/></row><row><dnorpattern>11</dn... (4 Replies)
Discussion started by: garboon
4 Replies

7. Shell Programming and Scripting

XML data extract

Hi all, I have the following xml document : <HEADER><El1>asdf</El1> <El2>3</El2> <El3>asad</El3> <El4>asasdf</El4> <El5>asdf</El5> <El6>asdf</El6> <El7>asdf</El7> <El8>A</El8> <El9>0</El9> <El10>75291028141917</El10> <El11>asdf</El11> <El12>sdf</El12> <El13>er</El13> <El14><El15>asdf... (1 Reply)
Discussion started by: nthed
1 Replies

8. Shell Programming and Scripting

Extract xml data

Hi all, I have the following xml file : <xmlhead><xmlelement1>element1value</xmlelement1>\0a<xmlelement2>jjasd</xmlelement2>...</xmlhead> As you can see there are no lines or spaces seperating the elements, just the character \0a. How can i find and print the values of a specific element?... (1 Reply)
Discussion started by: nthed
1 Replies

9. Shell Programming and Scripting

SED extract XML value

I have the following string: <min-pool-size>2</min-pool-size> When I pipe the string into the following code I am expcting for it to return just the value "2", but its just reurning the whole string. Why?? sed -n '/<min-pool-size>/,/<\/min-pool-size>/p' Outputting:... (13 Replies)
Discussion started by: ArterialTool
13 Replies

10. Shell Programming and Scripting

simerian XML Extract

The script following in this thread allows XML data to be located and extracted in a variety of forms from an XML data stream. Using this utility, it is possible to extract all manner of XML subsets and allow data to be post inserted into the "original" XML at any logical point. The pipe is... (2 Replies)
Discussion started by: Simerian
2 Replies
Login or Register to Ask a Question