LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2008, 02:39 PM   #1
wattz
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Rep: Reputation: 0
shell script to find data that's all in one line


Hi,

I'm having a problem searching through an XML file to find some different data, and then putting that data in a different file... the problem is, the information is all on one line and not easy to combine.
Below is the file i'm searching through. The Information I need to output is Bolded.

<?xml version="1.0" encoding="UTF-8"?>
<installconfig> <plugins> <plugin app="zzy" available="true" build="3329" installer="sarsy/setup.exe" name="sarsy set" required="false"/> </plugins> <customplugins> <customplugin app="zzy" available="true" build="301" installer="sarsy/XYZApp1.exe" name="XYZApp1" required="true"><events> <customplugin app="zzy" available="true" build="99" installer="sarsy/MYApp2.exe" name="MYApp2" required="true"><events/><menus> <patches> <patch app="zzy" build="4589" installer="sarsy/MY_patch_1221_2020.exe" patchnum="2020"/></patches> </installconfig>



Output should look like:
XYZApp1=301
MYApp2=99
Patch=2020


The name data will stay the same, but the build and patchnumber will change.

Any help would be appreciated!
 
Old 07-10-2008, 03:31 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
How does one distinguish one name field over another ? I see you've picked some name and some build fields, but haven't specified how to distinguish the fields you want from the same-named files you don't want.
 
Old 07-10-2008, 03:32 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Does it have to be a shell script? This would be much easier with a more powerful language like python or perl.
 
Old 07-10-2008, 03:33 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
And then you can use a perl XML parser module.
 
Old 07-10-2008, 04:24 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Another person ignoring the structure provided by XML. Use an XML parser (in perl XML::Parser, as Mr C. suggests), or any of several others that are available for other languages.
There are generally two flavors of XML parsers. Those which provide incremental reports via callbacks as the XML data is being parsed, and those that swallow the whole XML dataset and provide an API (usually using the XML DOM) for searching and modifying the in-memory XML data.
--- rod.
 
Old 07-10-2008, 04:48 PM   #6
wattz
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Great, thanks for the replies. I'll try the XML parser for perl.
 
  


Reply



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
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
shell script to find an word or words from a line rakesh.tandur Linux - General 5 05-13-2008 01:57 PM
How to identify a line and replace another string on that line using Shell script? Sid2007 Programming 10 10-01-2007 08:49 PM
shell script find a line and the next line (grep?) metalx1000 Programming 5 07-24-2007 08:41 PM
Shell Script that sorts data with number beginning on each line. sunksullen Programming 12 05-09-2007 03:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 PM.

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