| | |
modifying xml files using sed
![]() |
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Solved Threads: 0
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:
by the way, I use Linux sed, not Unix sed.(I'm not sure if differs)
thanks in advance...
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
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
Also, unless you are using variabls in the sed statement then you are better off using single quotes instead of double quotes.
Also, you can avoid having to escape the "/" by using a different separator
Shell Scripting Syntax (Toggle Plain Text)
sed -n 's;<idle>600</idle>;<idle>900</idle>;p'
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
----------------------------------------------
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
•
•
Join Date: Oct 2008
Posts: 95
Reputation:
Solved Threads: 5
Your problem is here
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.
Shell Scripting Syntax (Toggle Plain Text)
sed -n "s/<idle>600<\/idle>/<idle>900<\/idle>/p" $f >> $f
![]() |
Similar Threads
- Comparing 2 XML Files Using Perl (Perl)
- Java code to compare XML files (Java)
- How to compare folders of XML files in Perl using ExamXML (Perl)
- Eliminating Whitespace characters while parsing XML Files using DOM (Java)
- compare 2 xml files with csharp (C#)
- working with xml files without physically storing them. (ASP.NET)
- Reading stream with two xml files in (Java)
Other Threads in the Shell Scripting Forum
- Previous Thread: Script to identify current users on the system
- Next Thread: Change standard include path
| Thread Tools | Search this Thread |






