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, Pand D:
{cmds}: team group/y$/ {cmds}: executes a group of commands only if the line ends with yN: reads the next line in the pattern spaces/regex/replacement/: does replacement do not require flag gP: \n ( )D: \n
, :
sed -i ':a; N; s/y\ny/ya\ny/; {P; D}; ba' a6s
grymoire.com .