I have a long .XML file (60K or so lines) that I'm working with. I need bash to start the script and have a user input a name to be removed from the .XML file. I was thinking sed
but if there is a better option, I'm open to that too. Here is what I've got so far:
echo -n "Type media to remove and press [ENTER]"
read TARGET
while true; do
read -p "Are you sure you wish to remove $TARGET from the system?" yn
case $yn in
[Yy]* ) SED COMMAND HERE; break;;
[Nn]* ) echo "Cancelling..."; exit;;
* ) echo "---please answer [Y] or [N]";;
esac
done
And here is a section of the .XML file. Note that this section I'm posting repeats through the .XML hundreds of times. The only difference in the blocks are what I have labelled "corrupt" for this example.
<media>
<name>"corrupt"</name>
<parent>system</parent>
<location>/path/to/the/"corrupt".zip</location>
<video>/another/path/"corrupt".flv</video>
<images>
<image>
<type>saved</type>
<image-file>/yet/another/path/"corrupt".png</image-file>
</image>
</images>
</media>
In this example, I would wish to remove "corrupt" from the .XML file. I think it is important to say that there is only 1 instance of "corrupt" in the .XML file. Also, for other "corrupt_files", there are no spaces in the file names, only underscores or dashs.
So sed
would need to remove the entire xml block containing "corrupt" information, leaving no empty lines where it removed text, then the script would overwrite the current "media.xml" file.
I hope this question isn't confusing.