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
Facing issue while using xsltproc tp parse XML in bash shivashankar.g Shell Programming and Scripting 3 07-16-2009 12:29 PM
parse data using sh script moonbaby Shell Programming and Scripting 2 02-04-2009 10:43 PM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 04:17 AM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 01:25 PM
How do you parse a variable in a bash script? vertical98 Shell Programming and Scripting 3 03-18-2008 04:30 PM

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 07-16-2009
shivashankar.g shivashankar.g is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 5
Need to Parse XML from bash script

I am completely new to bash scripting and now need to write a bash script that would parse a XML file and take out values from specific tags.

I tried using xsltproc, xml_grep commands. But the issue is that the XML i am trying to parse is not UTF 8. so those commands are unable to parse my XML's or i am unable to find a woraround for that in xsltproc or xml_grep

Can some one help me in writing a direct script code (something other than utilities like xsltroc or xml_grep) that would pull me the value of the <url></url> tag irrespective the xml being well formed or not

This is the sample xml below

Code:
<site>
 <form>
        <url>http://www.bankoamerica.com/state.cgi?section=signin</url>
        <method>GET</method>
    </form>
</site>

Note: Use CODE-tags when displaying code, data or logs for better readability and to keep formatting like indention etc., ty.

Last edited by zaxxon; 07-16-2009 at 08:59 AM.. Reason: code tags
  #2 (permalink)  
Old 07-16-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
something like this :


Code:
sed -n 's|<url>\(.*\)</url>|\1|p'  file_name.xml

  #3 (permalink)  
Old 07-16-2009
shivashankar.g shivashankar.g is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 5
XML parsing in bash

Hi panyam
Thanks. This is working fine. The XML that i gave is a small chunk of a very big one. Can this sed command be changed so that it will give me only URL's that starts with http, https or www. I have some places where this url tag occurs and having diffeent values.

Code:
<site>
<form>
<url>http://www.bankofamerica.com</url>
<url>https://www.bankofamerica.com</url>
<url>www.bankofamerica.com</url>
<url>sitekey.bankofamerica.com</url
</form>
</site>

In the above example i just want the first 3 as a result and not the last one. Can you please help

Last edited by shivashankar.g; 07-16-2009 at 09:37 AM.. Reason: code tags
  #4 (permalink)  
Old 07-16-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474

Code:
sed -n 's|<url>\(.*\)</url>|\1|p' your_file.xml | egrep "^http|^www"

  #5 (permalink)  
Old 07-17-2009
shivashankar.g shivashankar.g is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 5
Thanks Panyam.
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 08:37 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