If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > xml file parsing

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-17-04, 22:24
kcryss kcryss is offline
Registered User
 
Join Date: Apr 2004
Posts: 8
xml file parsing

Hope someone here can help. I've completed two UNIX classes and am finally trying to make use of what I've learned.
I was given an xml file at work and asked if I could parse out bits of information. I did the original file in excel thinking it was a one time request. However, the request has become more frequent. I decided to write a script to do the parsing for me.
I've been able to use egrep and sed to get the data I need, but because the original data file has everything on seperate lines, my data is coming up on seperate lines as well. What can I do to put all the data from one record on one line?
Here's what I have so far:


read -p "File Name: " file
fileOut="New"$file
exec < $file
egrep "service_number|address|displayName|ProfileNam e" | sed 's/</:/g' |
sed 's/>/:/g' | sed 's/\//:/g' | cut -d: -f2,3 > $fileOut


the original file looks like this:


<cmd>
<Customer>
<service_number>xxxxxxxxxx</service_number>
<address>xxxxxxx xxxxxx xxx</address>
etc


The other catch is that there are more then 20 fields similar to what I listed above and not all records include all fields. If a field is null, it is not listed. So the data is not always in the same place.

Any idea's?
Reply With Quote
  #2 (permalink)  
Old 05-18-04, 11:50
kcryss kcryss is offline
Registered User
 
Join Date: Apr 2004
Posts: 8
Fixed! :-)

Never mind ... I figured it out (with help)

I piped it to:


awk -F: '$2 == "service_number" { print "\n" }
{ORS = "";OFS=""} { print ":",$3, " " }'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On