I have a file containing a list of replacement pairs (about 100 of them) which are used by sed
to replace strings in files.
The pairs go like:
{ cat replacement_list;echo "-End-"; cat YourFile; } | sed -n '1,/-End-/ s/$/³/;1h;1!H;$ {g
t again
:again
/^-End-³\n/ {s///;b done
}
s/^\([^|]*\)|\([^³]*\)³\(\n\)\(.*\)\1/\1|\2³\3\4\2/
t again
s/^[^³]*³\n//
t again
:done
p
}'
More for fun to code via sed. Try maybe for a time perfomance because this start only 1 sed that is recursif.
for posix sed (so --posix
with GNU sed)
explaination
³
and for list with -End-
) for an easier sed handling (hard to use \n in class character in posix sed.-End-³
, remove the line and go to final printt again
)t again
). T is needed because b
does not reset the test and next t
is always true.