shell script to edit file and delete entry

Can anyone provide me a shell script to edit a xml file and delete one entry.

To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script.

Thanks in advance
Tannu

you can do it with sed but only advanced sed comes with -i option where you can delete
the required line and save the edited file...
but in normal sed you have to redirect the edited file to someother file...
just go through the man page of sed... and awk...

1 Like

Depending on the format of the file, it can be done with sed or awk (or a pure shell script). For example:

If the entry is all on one line:

sed '/<entry>..</entry>/d' FILENAME

If it's on more than one line with nothing else on those lines:

sed '/<entry>/,</entry>/d' FILENAME

Hi
Thanks for your reply.
Actually the xml file looks like
#vi package.xml
<rpm>drivers-3.6.22-${release}.${arch}.rpm</rpm>
..
..
#
And if I want to delete this entry then what should be the sysntax?

I tried

sed '/<rpm>drivers-3.6.22-${release}.${arch}.rpm</rpm>/d' /root/packages.xml

but i did't worked.Can you please let me know.

Appreciate your help.

You need to escape the slash in the pattern:

sed '/ <version>3.2<\/version> /d'   FILENAME

Hi

Thanks.

But it copies everything to output file that is package.xml to output.txt.

sed '/<rpm>driver-block-cciss-3.0.14-${release}.${arch}.rpm<\ /rpm> /d' /root/package.xml > /root/output.txt

Thanks for your help.

Hi

Thankyou so much it worked.