如何复制特定文本下方的特定行?

How to copy particular lines below particular text?

假设我有长文本文件 output1output2output3。在所有输出文件中,某处是 "My Name is Rock (static)" 在该文本下方有一些值,例如

"My Name is Rock (static)"
10 20 30
-10 0.5 00
3.0 0.0 0.0 (different for all output file)

如何将第("My Name is Rock (static)")行下方第三行第二列复制到新文件中?

记住所有输出文件的行号都不同。

awk 'c{c--;if(!c) print }/My Name is Rock \(static\)/{c=3}' ./output1 ./output2 ./output3

说明

  • /My Name is Rock \(static\)/{c=3}:当看到"My Name is Rock (static)"时,设置c为3
  • c{...}:如果计数器 c 不为零,则执行 ...(注意,c 从 0 开始)
  • c--;if(!c) print :递减计数器,如果计数器现在为零,打印当前行的第二个字段