Usage GNU sed
(full thanks for this wonderful solution belongs to @Sundeep, thanks):
sed -i '/y$/ {N; s/y\ny/ya\ny/; P; D}' a6s
To work on multiple lines with sed
, you must use the commands N
, P
and D
:
{cmds}
: team group/y$/ {cmds}
: executes a group of commands only if the line ends with y
N
: reads the next line in the pattern spaces/regex/replacement/
: does replacement do not require flag g
P
: \n
( )D
: \n
, :
sed -i ':a; N; s/y\ny/ya\ny/; {P; D}; ba' a6s
grymoire.com .