Register
It is currently Sat Sep 20, 2014 5:58 am

Search and replace between two files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri Nov 19, 2010 6:48 am   

Joined: Fri Nov 19, 2010 6:38 am
Posts: 3
I have a xml file (xml) and a text file(txt) with two collumns, one with a id and the second with a name
the xml file contains ids witch match ids in the txt file.

What i want do to is to replace the ids in the xml file with the name from the text file.

I know awk can reed the file and place the content in variables and i know sed can replace the content using these two variables.
I just doent know how to use them togheter.


Top
 Profile  
 PostPosted: Fri Nov 19, 2010 2:38 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Please post a relevant example of both files


Top
 Profile  
 PostPosted: Mon Nov 22, 2010 12:44 am   

Joined: Fri Nov 19, 2010 6:38 am
Posts: 3
xml fil:
<feed name="Anb/boligmagasin">
<source sectionid="42208">
<filter>
</filter>
</source>
<destination id="43258">
<placement pri="1" desk="webdesk">
</placement>
</destination>
</feed>


Text file :
40672 bildeserier_nyheter
40673 bildeserier_motor
40674 bildeserier_fotball
40675 bildeserier_underholdning
40676 bildeserier_vitenskap


Top
 Profile  
 PostPosted: Mon Nov 22, 2010 12:46 am   

Joined: Fri Nov 19, 2010 6:38 am
Posts: 3
I want to replace the id for sectionid and destination id with the names from the text file.


Top
 Profile  
 PostPosted: Mon Nov 22, 2010 7:57 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
If your XML file is not formated always the same way (whitespace, newlines), then an XML parser would be the right tool. You can have a look at http://xsh.sourceforge.net for a shell that can handle XML.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP