我能够从文本文件中提取这些行
TBL Papers
Papers_ShortName "TPJ341861"
Papers_Name "BANK 240314 341861 "
MMInstrumentType P "Discounted Paper"
但想插入一个新行(匹配TBL论文前的文字)。看到预期的产出
ACTION "INS"
TBL Papers
Papers_ShortName "TPJ341861"
Papers_Name "BANK 240314 341861 "
MMInstrumentType P "Discounted Paper"
我该怎么做?感谢
答案 0 :(得分:1)
使用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"
此代码将在模式TBL Papers
上方添加一行,然后将所有内容打印出来。
答案 1 :(得分:0)
awk '/TBL Papers/{ print "ACTION \"INS\"" } 1' file