The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 view the contents of .gz file without extracting the file? amitkhiare Shell Programming and Scripting 10 12-18-2008 05:59 AM
Extracting from a tar file nmalencia UNIX Desktop for Dummies Questions & Answers 1 03-22-2008 06:42 AM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM
[Splitting file] Extracting group of segments from one file to others ozgurgul Shell Programming and Scripting 1 09-14-2006 12:17 PM
extracting from a tar file Reza Nazarian UNIX for Dummies Questions & Answers 4 03-24-2006 05:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2007
pujansrt pujansrt is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 5
Question extracting XML file using sed

Hello folks

I want to extract data between certain tag in XML file using 'sed'
<xml>
.........
..........
<one>XXXXXXXXXXXXXXXXXXXX</one>
......

Anyone ?Thank you
  #2 (permalink)  
Old 06-28-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
typeset -i mCnt
mFlag='N'
while read mLine
do
  mCnt=`echo $mLine | egrep -c '<one>'`
  if [ $mCnt -ne 0 ]; then
    mFlag='Y'
  fi
  if [ "$mFlag" = "Y" ]; then
    mOutLine=`echo $mLine | sed 's:<one>::;s:</one>::'`
    if [ "$mOutLine" != "" ]; then
      echo $mOutLine
    fi
  fi
  mCnt=`echo $mLine | egrep -c '</one>'`
  if [ $mCnt -ne 0 ]; then
    mFlag='N'
  fi
done < input_file
  #3 (permalink)  
Old 06-28-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Could you please post more appropriate input and output ?
  #4 (permalink)  
Old 06-28-2007
pujansrt pujansrt is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 5
Thumbs up

<MiniTable id="BrowserMiniTable">
<Row>
<Value>66.17%</Value><Key>InternetExplorer</Key>
</Row>
<Row>
<Value>27.39%</Value><Key>Firefox</Key>
</Row>
</MiniTable>

<MiniTable id="ConnectionTable">
<Row>
<Value>4.56</Value><Key>InternetExplorer</Key>
</Row>
<Row>
<Value>4.23</Value><Key>Firefox</Key>
</Row>
</MiniTable>
------------------------------------------------------------------
There are many <MiniTable> but I wanted only first one i.e. <MiniTable id="BrowserMiniTable"> 's content only in following form---

OUTPUT:
Browser----%
InternetExplorer----66.17
Firefox----27.39

Thanks dude
  #5 (permalink)  
Old 06-28-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Pujansrt,
Now you learned how important it is to follow the rules:
Quote:
(A) Include as many pertinent details as possible in your post.
...<more left out>...
The solution that I gave works with your first requirement.
  #6 (permalink)  
Old 06-29-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed -n "/BrowserMiniTable/,/MiniTable/s/<Value>\([^%]*\)%*<\/Value><Key>\(.*\)<\/Key>/\2-----\1/p" filename
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:06 PM.


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