I am looking for a command-line tool to do multi-line replacements.
Something like:
the-tool --search file-containing-lines-to-match \
--replace file-containing-new-lines < original-file > new-file
Does anyone know of a tool like this?
I can do it with sed like:
sed -e :a -e '$!N;s/^string1\nstring2$/string3\
string4/;ta' -e 'P;D'
But I will need to all the file-containing-lines-to-match converted to
my lhs (left hand side) of expression and then convert the
file-containing-new-lines to the rhs. Note that some seds don't allow \n
in rhs, so that is why \ and literal ^J there.
I have many different inputs for the text to replace and the new text.
And I have hundreds of files to edit. The text to replace may have
characters that would need to be escaped so don't appear as regex, like
. or * etc. But I can pre-escape those if needed. I may have parts that
need to be regular expressions, for example there may be some word that
is different in each and I don't want to prepare a new
file-containing-lines-to-match for minor differences.
There must be a tool like this already. I see GUI tools, but looking for
something I can use via the shell. If not, I guess I can write a
wrapper around sed for this.
Thanks
Jeremy C. Reed
echo 'EhZ[h ^jjf0%%h[[Zc[Z_W$d[j%Xeeai%ZW[ced#]dk#f[d]k_d%' | \
tr '#-~' '\-.-{'