The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2008
sharpi03 sharpi03 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 5
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!
  #2 (permalink)  
Old 10-24-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0