Assuming that you get the above diagnostic when running the script vgersh99 suggested:
awk -F'"' '{$(NF-3)=$(NF-1)}1' OFS='"' myFile
it is telling us that line number 2 in your input file (the one named web.xml ) does not contain any double-quote ( " ) characters. And, since the sample input that you showed us had four pairs of double-quotes on every input line, it wasn't prepared to handle input in a different format.
If you can't be bothered to accurately describe the format of the input data your script will be processing, we have to assume that you will be able to modify any suggestions provided to weed out (or otherwise process) lines in your input file(s) that do not match the format of the data you said you wanted to process.
Mmmm...
After your explanation is really more clear. But push me to ask again.
I am asking to use one command like sed or awk because before I used a different command and I am sure was right, the command was:
xml ed --inplace -u "//channel/@site_id" -x "string(../@xmltv_id)" WebGrab++.config.xml
Using it, I had a similar error like now.
The error is:
WebGrab++.config.xml:2.2: Extra content at the end of the document
So I am thinking the errors I am having are not about the commds I am giving (awk or xmlstarlet) but are about the commands I gave before. The file is really big and the original format is like this:
If I apply both command (xmlstarlet or awk) on the original file they are working, but is not what I want. To fix the document and have the document like I published at the first post I need use some commands before, the commands are:
# Delete everything between "<channel" and "xmltv_id"
sed -ri 's/( <channel )(.*)(xmltv_id)/\1\3/g' WebGrab++.config.xml
# Add after "<channel" the fields "<channel update="i" site="merge-xmltv" site_id="" "
sed -i 's/ <channel / <channel update="i" site="merge-xmltv" site_id="" /g' WebGrab++.config.xml
# Delete lines from 1 to 136
sed -i '1,136d' WebGrab++.config.xml
# Delete last line
sed -i '$d' WebGrab++.config.xml
# Delete all lines contain comments
sed -i '/^</d' WebGrab++.config.xml
# Delete all empty lines
sed -i '/^ *$/d' WebGrab++.config.xml
# Delete all comments till the end of the line
sed -i 's/<!--.*//' WebGrab++.config.xml
# Delete all blank space or tab at the end of the line
sed -i 's/[[:blank:]]*$//' WebGrab++.config.xml
Afer I applied all this procedure, the file look like damage, like sed did something wrong after the second line.
It is not much clearer to me WHAT you really need in the end, but Don Cragun's analysis proves right when seeing your second sample input file.
You might want to safeguard your script by adding some tests for applicability (or justification) of the modifications: