I am trying to replace a line containing the Pattern using gawk
, with a set of lines. Let's say, file aa
contains
aaaa
ccxyzcc
aaaa
ddxyzdd
I'm using gawk to replace all lines containing xyz with a set of lines 111\n222, my changed contents would contain:
aaaa
111
222
aaaa
111
222
But, if I use:
gawk -v nm2="111\n222" -v nm1="xyz" '{ if (/nm1/) print nm2;else print $0}' "aa"
The changed content shows:
aaaa
ccxyzcc
aaaa
ddxyzdd
I need the entire lines those contain xyz
i.e. lines ccxyzcc
and ddxyzdd
having to be replaced with 111
followed by 222
. Please help.