Wednesday, September 20, 2017

Using Sed command to search and replace text in XML file or any other file .




Using Sed command to search and replace text in XML file or any other file .


To replace entire line with a specific text/string in linux by using sed command

Syntax:

sed -i 's/.*<TEXT>.*/<TEXT TO BE ON REPLACED LINE>/' *.xml

Replace below placeholders completely to put your required string/text in above syntax.

<TEXT>
<TEXT TO BE ON REPLACED LINE>

Please be aware of the escape sequence while executing the command. 


eg. Here I am replacing entire line which contains <lastmod> tag with <lastmod>2017-07-19T15:09:05+08:00</lastmod>

So please see that closing </lastmod> tag is having `\` (escape sequence). In you case it may vary depending upon your requirement.

sed -i 's/.*<lastmod>.*/<lastmod>2017-07-19T15:09:05+08:00<\/lastmod>/' *.xml

Be specific to the syntax and consider each and every comma and other preposition.









No comments:

Post a Comment

Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...