943,708 Members | Top Members by Rank

Ad:
Jul 6th, 2009
0

modifying xml files using sed

Expand Post »
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:
Quote ...
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...
Similar Threads
Reputation Points: 16
Solved Threads: 0
Light Poster
xyzt is offline Offline
35 posts
since Apr 2008
Jul 6th, 2009
0

Re: modifying xml files using sed

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 6th, 2009
0

Re: modifying xml files using sed

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.
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Script to identify current users on the system
Next Thread in Shell Scripting Forum Timeline: Change standard include path





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC