modifying xml files using sed

Reply

Join Date: Apr 2008
Posts: 31
Reputation: xyzt is an unknown quantity at this point 
Solved Threads: 0
xyzt xyzt is offline Offline
Light Poster

modifying xml files using sed

 
0
  #1
Jul 6th, 2009
Hello,

I have lots of xml files in the same format and I need to modify a xml tag in these files.
i loop over the files and apply sed to the files to make the modification but CPU goes to %100 while doing this. I think I'm doing something wrong. Here is my onliner:
for f in $( find . -name "*.xml" ); do sed -n "s/<idle>600<\/idle>/<idle>900<\/idle>/p" $f >> $f; echo "file:" $f;done
by the way, I use Linux sed, not Unix sed.(I'm not sure if differs)

thanks in advance...
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,356
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: modifying xml files using sed

 
0
  #2
Jul 6th, 2009
Do you really want to copy the modified line to the end of the original file so that the same tag exists twice with differing values?

Also, you can avoid having to escape the "/" by using a different separator
Shell Scripting Syntax (Toggle Plain Text)
  1. sed -n 's;<idle>600</idle>;<idle>900</idle>;p'
Also, unless you are using variabls in the sed statement then you are better off using single quotes instead of double quotes.
Last edited by masijade; Jul 6th, 2009 at 12:36 pm.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 95
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 5
fpmurphy fpmurphy is offline Offline
Junior Poster in Training

Re: modifying xml files using sed

 
0
  #3
Jul 6th, 2009
Your problem is here
Shell Scripting Syntax (Toggle Plain Text)
  1. sed -n "s/<idle>600<\/idle>/<idle>900<\/idle>/p" $f >> $f
You need to use either the -i option to GNU sed to permit in place editing or save the output to a temporary file and then cp that temporary file to $f.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC