user3269979
user3269979

Reputation: 11

how to insert a new line with text before the match

I was able to extract these lines from a text file

TBL Papers
Papers_ShortName "TPJ341861"
Papers_Name "BANK    240314 341861    "
MMInstrumentType P "Discounted Paper"

but wanted to insert a new line( text before the match TBL Papers). see expected output

ACTION "INS"
TBL Papers
Papers_ShortName "TPJ341861"
Papers_Name "BANK    240314 341861    "
MMInstrumentType P "Discounted Paper"

How do I do that ? thanks

Upvotes: 0

Views: 93

Answers (2)

Ed Morton
Ed Morton

Reputation: 203169

awk '/TBL Papers/{ print "ACTION \"INS\"" } 1' file

Upvotes: 0

Jotne
Jotne

Reputation: 41446

Using awk

awk '/TBL Papers/ {$0="ACTION \"INS\"" RS$0}8' file
ACTION "INS"
TBL Papers
Papers_ShortName "TPJ341861"
Papers_Name "BANK    240314 341861    "
MMInstrumentType P "Discounted Paper"

This code will add a line above pattern TBL Papers and then print everything out.

Upvotes: 1

Related Questions