![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to extract values b/w two delimiters | tsaravanan | Shell Programming and Scripting | 5 | 09-16-2008 12:40 PM |
| Converting Binary decimal coded values to Ascii Values | gaur.deepti | UNIX for Advanced & Expert Users | 3 | 04-02-2008 01:33 PM |
| Extract values from log file | wdympcf | Shell Programming and Scripting | 5 | 08-10-2007 04:52 AM |
| I need to extract last column of a file and compare the values | vukkusila | Shell Programming and Scripting | 4 | 08-04-2007 12:21 PM |
| Last element from cut | oldtrash | UNIX for Dummies Questions & Answers | 3 | 07-05-2005 06:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Extract XML Element Values
I have a rather large file with XML-style content. Each line contains one full XML entry. For example:
1:<Message><DNIS>1234</DNIS><UCID>3456</UCID><TransferGroup>XYZXYZ</TransferGroup></Message> 2:<Message><DNIS>9999</DNIS><UCID>2584</UCID><TransferGroup>ABCABC</TransferGroup></Message> ..... I'm trying to figure a way to be able to go through the file, pull pertinent info, and print the output in a separate file delimited with commas: output.txt: 1234,3456,XYZXYZ 9999,2584,ABCABC I was able to achieve this via a series of greps with cuts for each value I want, but it takes far too long to run. I have 10,000+ entries to retrieve. I'm not very good with awk or sed or anything else that could prove more efficient. Can anyone help? Thanks! |
|
||||
|
One sed should be enough, try: Code:
sed '
s#^<Message><DNIS>##
s#</DNIS><UCID>#,#
s#</UCID><TransferGroup>#,#
s#</TransferGroup></Message>$##
' input.txt > output.txt
Last edited by Annihilannic; 10-24-2008 at 02:37 AM.. Reason: Changed slashes to hashes |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|