Solved

I need a parsing script...or a command with awk, not sure

Posted on 2014-04-27
5
288 Views
Last Modified: 2014-04-28
This is an XML file exported from my text. I need a script to parse it...as an example below this XML file

 <sms protocol="0" address="4053234432" date="1388706261627" type="2" subject="null" body="I'm heading home" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="null" readable_date="Jan 2, 2014 5:44:21 PM" contact_name="Mom" />
  <sms protocol="0" address="9726768860" date="1388786728946" type="1" subject="null" body="Tony_new_number - How are you?" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="null" readable_date="Jan 3, 2014 4:05:28 PM" contact_name="Tony Comp" />
  <sms protocol="0" address="9726768860" date="1388786847009" type="1" subject="null" body="Tony_new_number -  Fine.just anticipating getting back. I'm ready. Although I'll miss her." toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="null" readable_date="Jan 3, 2014 4:07:27 PM" contact_name="Tony Comp" />

I would like it to read like the following

4053234432 "I'm heading home" Jan 2, 2014 5:44:21 "Mom"
9726768860 "Tony_new_number - How are you?" "Jan 3, 2014 4:05:28 PM" ""Tony Comp"
"9726768860" "Tony_new_number -  Fine.just anticipating getting back. I'm ready. Although I'll miss her." "Jan 3, 2014 4:07:27 PM" "Tony Comp"

So, I basically just need the:
The fields: address="xxx" body="xxxx" readable_date="xxxxx" and contact_name="xxx"

Thanks for any help
0
Comment
Question by:Viclyn
  • 2
  • 2
5 Comments
 
LVL 61

Expert Comment

by:gheist
Comment Utility
lex/bison seems more appropriate to dig randomly ordered fields you have.
0
 

Author Comment

by:Viclyn
Comment Utility
I don't think it's very random. There are hundreds of entries, and they take on the format:

<sms

protocol=""
address=""
date=""
type=""
subject=""
body=""
toa=""
sc_toa=""
service_center=""
read=""
status=""
locked=""
date_sent=""
readable_date=""
contact_name=""

/>

I just want these four field:

address=""
body=""
readable_date=""
 contact_name=""
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
Comment Utility
sed 's/^.* address="\([0-9]*\). .* body=\("[^"]*"\) .* readable_date=\("[^"]*"\) contact_name=\("[^"]*"\) .*/\1 \2 \3 \4/' input_file

Open in new window


I've assumed you don't want the double quotes round the phone number (1 of your output lines has the quotes, the other 2 don't!)
0
 
LVL 19

Expert Comment

by:simon3270
Comment Utility
My answer does assume a couple of things:
- that each entry is on one line, as in your example text
- that none of the fields contain double-quote characters.  What happens if they do?
0
 

Author Closing Comment

by:Viclyn
Comment Utility
Very nice. Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now