I am trying to insert a line after the Pattern using gawk
.
Let's say, file aa
contains
11
22
33
11
22
33
I'm using gawk to insert 222 only after first 22, i.e. after insertion, my aa file would contain:
11
22
222
33
11
22
33
But, if I use:
gawk -v nm=222 '/22/ {if (done++ == 0) print;print nm;next}1' aa
The file aa contains:
11
22
222
33
11
222
33
(I don't want second replacement of 22 by 222 and like to retain 22 as-is, and no more insertion, i,e,. insert 222 only once after first 22. Please help.