0

I have these lines to delete in many files, but the sed command on CentoOS doesn't replace the whole sentence.

Example of text:

<!-- insert this +1 -->
<div style="float:left"><g:plusone size="medium" href="http://xxxxx/xx.com"></g:plusone></div>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{lang: 'it'}
</script>


sed '/<\!-- insert this +1 -->/d' FILENAME.html
sed '/<div style=\"float:left\"><g:plusone size=\"medium\" href=\"http:\/\/xxxxx\/xx.com\"><\/g:plusone><\/div>/d' FILENAME.html
sed '/"<script type=\"text\/javascript\" src=\"https:\/\/apis.google.com\/js\/plusone.js\">/d' FILENAME.html
sed '/{lang: 'it'}/d' FILENAME.html
sed '/<\/script>/d' FILENAME.html

A single command works, but replaces </script> and other matches in the file.

I tested with | / -e / perl -0pe / a lot of combinations of ''"", but it doesn't work. How it is possible to replace it by eliminating only that part?

VecnaC1
  • 1
  • 1
  • Also, you may want to pipe those `sed` commands instead, write to a different file, remove the original one, rename the processed one to the original name. – Federico klez Culloca Feb 27 '19 at 16:42
  • I know that the file can be edited with -i in place -i.back for save in other file. I use | but not work. without -i displays a preview of the change – VecnaC1 Feb 27 '19 at 16:50
  • use the range pattern: `sed '/<\!-- insert this +1 -->/,/<\/script>/d' FILENAME.html` – jxc Feb 27 '19 at 17:56
  • @jxc thank you so much with character , sed leave a range of string. I have no chance to answer but your answer is my solution. Combine and other solution marked as duplicate remove other combination in my many file. your solution take the range and delete – VecnaC1 Feb 28 '19 at 10:11

1 Answers1

0

just simple as that

just check the line number of that lines and then delete it using the below command. for example they are at line 7 and 9 :

sed '7,9d' FILENAME.html
Aman Gupta
  • 400
  • 1
  • 9