I have a file example.txt with content look like this:
<TAG>
1
2
3
</TAG>
and I use a sed command to replace everything between <TAG></TAG> as below:
sed -e 's/\(<TAG>\)[^<]*\(<.*\)/something/g' example.txt > example.txt.new
But unfortunately, the command failed to replace as i want, it only work if the content between the tags are not break into multi-line. Could someone please explain how to solve this case?
Your awk command doesn't replace the content between the tags, but it deletes them. Now, i can use sed command to add new content as expect. Thanks again for your help.
I really appreciated for your help dennis. But the Franklin's command works very well in my situation. Maybe i'll need your helps for my future's troubles, but i owed you this time
Thanks. But I cannot change the filename, and I need to do it recursively. I have .html and .htm files in many subdirs, all of which need to have this code removed but cannot have filenames changed or otherwise modified. Thank you for your kind help and apologies for not being more knowledgeable on this
thers is a flaw in my script, it will remove all text( other than b/w tags, which it should not in all cases), better use the solution suggested by Franklin. The below code will do the job for you. Test is throughly before using in production.
for i in `find . -name "*\.html"`
do
awk '/<AFFILIATECODEBEGIN>/{p=1;print;print"something in b/w tags";next}/<\/AFFILIATECODEBEGIN>/{p=0;print;next}!p' $i >> $i"_Chng"
mv $i"_Chng" $i
done