Tell me how to solve the problem on bash with the sed command

There is a file with the content:

бла бла бла ... /*033cf*/ @include "\x2fhom\x65/mg\x6etep\x6co/m\x67nte\x70lo.\x72u/d\x6fcs/\x6dodu\x6ces/\x6dod_\x65xt_\x6denu\x6dati\x63/js\x2ffav\x69con\x5fd38\x3368.\x69co"; /*033cf*/ ... бла бла бла 

The task is to delete everything starting with @include "\x2 and ending ;

  • in your example, the fragments @include "\x2 and ; are in one line, and the question is about a lot of lowercase text. Please specify what you mean. - aleksandr barakin
  • one
    without waiting for an answer to his comment, but seeing that the answer came up, having nothing to do with a lot of line writing, he removed the word “multi-line” from the question title. - aleksandr barakin
  • Apparently, by "multi-line" the author had in mind the presence of multiple lines that need to be replaced. - zombic
  • I beg your petition! there was a multi-line I will enter in the second example, which I forgot to publish absently: $ iCode = "ffff"; and on the second line is $ iCode. = "fffff"; - Angel of Tender Passion
  • \x2f most likely meant in the template. /home/mgnteplo/mgnteplo.ru/docs/modules/mod_ext_menumatic/js/favicon_d38368.ico - 0andriy

2 answers 2

If sed doesn’t matter in principle, I suggest an option with grep :

 grep -v '^@include\ "\\x2.*;$' filename 

grep will show the filename, and -v will remove lines starting with @include "\x2 and ending ;

  • Not important, just grep could not write correctly! A big THANK YOU - Angel of Gentle Passion
  • one
    Actually and on sed simple: sed -i -e 's / ^ @ include \ "\\ x2. *; $ // g' filename` - zombic

delete all lines containing фрагмент1 , and then фрагмент2 :

 $ sed -i '/фрагмент1.*фрагмент2/d' файл 

delete all lines beginning with фрагмент1 and ending with фрагмент2 ( ^ - binding to the beginning of the line, $ - to the end):

 $ sed -i '/^фрагмент1.*фрагмент2$/d' файл 

delete only parts of lines starting from фрагмент1 and ending in фрагмент2 :

 $ sed -i 's/фрагмент1.*фрагмент2//' файл 

If inside the fragments there are symbols / or \ , you should add the symbol \ in front of them.

  • [code] sed -i 's / fragment1. * fragment2 //' file [/ code] And how can you make sure that only the characters between fragment1 and fragment2 are deleted without deleting fragment1 and fragment2? - Mashulechka