Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-26-2010, 12:21 AM   #1
LQ Newbie
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
Smile Edit an XML from bash script


I am new to shell script and need to edit an xml form script.
The XML file is something like

If the user selects element1, the script should modify only element1 values and not element2 values.
I need it to be done from bash script. I can't use python or perl for the same. Please provide me a way to do so.

Old 02-26-2010, 01:02 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
If this is "the real world" - use Python or Perl. That's the only sane approach.

If this is homework - good luck!

Hint: have you covered "sed" yet in class?

Last edited by paulsm4; 02-26-2010 at 01:03 AM.
Old 02-26-2010, 01:26 AM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
Hi, and welcome to LQ!

I concur ... there's proper programming languages with ready
made extensions for handling XML decently; if that's REALLY
not an option, for whatever reason, have a look at awk and its
ability to handle ranges.

Old 02-26-2010, 01:38 AM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
An interactive script instead of a filter seems to indicate a homework problem. Could you post what you have tried?

And why do they teach bash programming as if it were msdos?
Old 02-27-2010, 01:08 PM   #5
Senior Member
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
I recently needed to do some simple manipulation of XML from a bash script and found xmlstarlet. You don't say what distro you're using, but it's in the Ubuntu and openSUSE repositories.

Though given this is (almost certainly) homework they're probably expecting you to do it using bash builtins and GNU userland tools rather than using a tool specifically designed for manipulating XML.
Old 03-05-2010, 12:58 AM   #6
LQ Newbie
Registered: Feb 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Smile Thanks

Thanks for the reply.

I can assure you it's not a homework problem, rather i wanted to learn how to do it.

I used "sed" with it's line number characteristics to perform the required function.

Old 03-05-2010, 03:28 AM   #7
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
The two tools worth considering for this in shell scripting are awk and sed.

As others have pointed out, and you already know, there are better ways to handle XML. Both perl and python have good libraries for this.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Force Script (Bash) to Edit File? carlosinfl Linux - General 3 10-02-2008 11:57 AM
help with complex bash script-XML handling panoskan Programming 4 09-18-2008 08:19 PM
Bash script to strip some content from XML file. musther Programming 10 10-14-2007 06:47 PM
Parse XML in bash script MikeyCarter Linux - Software 1 02-16-2007 02:19 PM
Bash script to edit text file snowman81 Linux - Desktop 2 01-10-2007 04:33 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration