我有如下文件内容:
aaa accounting exec ...
aaa accounting exec ...
aaa accounting commands ..
aaa accounting commands ..
aaa accounting commands ..
aaa accounting commands ..
aaa accounting commands ..
aaa accounting commands ..
aaa accounting network ..
aaa accounting connection ..
aaa accounting system ..
!
aaa accounting exec default
action-type start-only
group something+
!
aaa accounting exec default stop-only group tacacs+
输出应该是这样的:
aaa accounting exec ..
aaa accounting exec ..
aaa accounting exec default
action-type start-only
group something+
!
aaa accounting exec default stop-only group tacacs+
我想获得以下两种模式之间的输出:
Start Pattern: /aaa accounting exec .+/
End Pattern: /!/
产生上述输出的最简单的 perl 代码是什么?
答案1
答案是:
perl -ne ' if($p==1){if(/^ /){ print; next;} elsif(/^!/){print;}$p=0}
if(/aaa accounting exec .+/){print;$p=1}' text.txt
在哪里文本.txt是包含问题中提到的上述文本的文件。