我正在尝试创建一个 bash 脚本,该脚本将使用 egrep 从文件中 grep 行。我已经创建了应该对我想要的信息进行分组的正则表达式,问题是试图获得输出。我一直在使用以下命令对其进行测试,但运行时没有打印任何内容。如何打印 -{80} 和 Disconnected 之间的多行?
egrep -E "^-{80}$\r?\n?([:ascii:]*)Disconnected from Server" testing.txt
Run Code Online (Sandbox Code Playgroud)
文件:testing.txt
Connected to the server: name here
Some header text.
More text to go though...
--------------------------------------------------------------------------------
The information that I want, would be in here;
Including this line as well #$
and this one.
Disconnected from Server...
Run Code Online (Sandbox Code Playgroud)
使用 awk 之类的工具可能会更好。
awk '/^----+$/ {flag=1;next} /Disconnected from Server/{flag=0} flag {print}'
Run Code Online (Sandbox Code Playgroud)
请参阅:http : //nixtip.wordpress.com/2010/10/12/print-lines-between-two-patterns-the-awk-way/
归档时间: |
|
查看次数: |
994 次 |
最近记录: |