有一个命令给我一个很长的输出。我只想提取其中的一行。该行发生变化,但所需行之前的两行始终相同。如何仅通过搜索前一行来提取这一行:命令输出示例如下:
  foo-bar blahblah
  ===============
    foo bar foo bar foo bar.
  this string is always the same (search string)
  ===============
    the desired line is here
==========
foofoofoo
==========
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了
awk '/this string is always the same/{p=1} NF{out=$2}  END{if(p==1){print out}}'
Run Code Online (Sandbox Code Playgroud)
没有 if 部分但它不起作用
我需要的结果是这样的:
the desired line is here
Run Code Online (Sandbox Code Playgroud)