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...

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

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.

Your problem is here

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.