-4

I had posted a question on bash: insert a line after a pattern using gawk

How do I insert more than one line after a line containing a pattern?

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • well, use the same solution but print the string containing those multiple lines or use multiple print statements... – ewcz Oct 03 '16 at 19:02
  • I can't believe this absolutely minimal "question" has 2 answers already! Read [ask]. – Ed Morton Oct 03 '16 at 19:19

2 Answers2

1

String together your prints like awk '<condition>{print $0; print "222"; print "223"; print "224"}

Or use the newline character:

awk '<condition>{print $0"\nthis is a line\nthis is a secondline\nthis is a thirdline"}

JNevill
  • 46,980
  • 4
  • 38
  • 63
1

I modified nm1 from 222 to 222\\n333 to add multiple lines at once (the command is from the answer of your original post )

awk '1; $1==nm2 && !a++ {print nm1}' nm1=222\\n333 nm2=22 file

output:

11
22
222
333
33
11
22
33
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125