如何过滤“cat”输出以仅显示部分文本?

如何过滤“cat”输出以仅显示部分文本?

我正在尝试找到一种方法来过滤命令的输出,cat以便仅显示两点之间的文本。我需要将其放在脚本中。

更确切地说,给出以下示例文本

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus        
et magnis dis parturient montes, nascetur ridiculus mus. Donec quam
felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla
consequat massa quis enim. Donec pede justo, fringilla vel, aliquet
nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. 

-------------
Release Notes
-------------

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus        
et magnis dis parturient montes, nascetur ridiculus mus. Donec quam
felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla
consequat massa quis enim. Donec pede justo, fringilla vel, aliquet
nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. 

------------
Known Issues
------------

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus        
et magnis dis parturient montes, nascetur ridiculus mus. Donec quam
felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla
consequat massa quis enim. Donec pede justo, fringilla vel, aliquet
nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. 

我需要输出仅有的显示之间的文本

-------------
Release Notes
-------------

------------
Known Issues
------------

块。

我尝试了一些方法,grep但是由于文本分布在多行上,所以它不起作用(或者至少我无法让它起作用)。

答案1

尝试 awk:

awk '/Release Notes/,/Known Issues/' file | head -n -3 | tail -n +4

第一个命令提取“Release notes”和“Known issue”之间的文本,head 和 tail 用于从示例中删除第一行和最后一行。如果您不想让 awk 打印匹配的行,则应使用:

awk '/^Release Notes$/{flag=1;next}/^Known Issues$/{flag=0}flag' file

相关内容