suse linux 10 here.
I have two xml files here and both contain <sf> and </sf> tags in almost beginning and towards the end fo the files.
I need to remove the </sf> tag from the first file and the <sf> from the second file and combine both the files into one. I have tried the following script but i am getting a resulting output file which is empty. Please advise.
#!/bin/sh
# this is myscript.sh
if (test -e file1.xml) && (test -e file2.xml)
then
cat file1.xml|grep -v '</sf>'>billprint.xml
cat file2.xml|grep -v '<sf>'>>billprint.xml
fi
Just FYI: all my xml code is in one line
If all of the xml is on one line then the grep -v will remove your whole line from the output... since it is all on one line I would use sed to remove the </sf> and <sf> from the files...
$ cat t2.txt
<sf>thi si sa test</sf>
$ cat t2.txt | sed 's/<\/sf>//g'
<sf>thi si sa test
$ cat t2.txt | sed 's/<sf>//g'
thi si sa test</sf>
$
see how that works...
I only want to remove the tags from these files, not the entire lines that contain these tags.
Using "sed" will replace all appearances of "<sf>" and "</sf>" in your file. Then you can append them together.
Since your data is all on one line then "grep -v" will not work for what you want.
sethcoop,
your suggestion worked like a charm. I never knew that -v option of grep would remove the entire line.
Thanks a lot.