我正在尝试创建一个bash脚本,它将使用egrep从文件中grep行.我创建了应该将我想要的信息分组的正则表达式,问题是尝试获取输出.我一直用以下命令测试它,但运行时没有打印.如何在 – {80}和断开连接之间打印多行?
egrep -E "^-{80}$\r?\n?([:ascii:]*)Disconnected from Server" testing.txt
文件: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...
你可能最好使用像awk这样的工具.
原文链接:https://www.f2er.com/bash/385264.htmlawk '/^----+$/ {flag=1;next} /Disconnected from Server/{flag=0} flag {print}'
见:http://nixtip.wordpress.com/2010/10/12/print-lines-between-two-patterns-the-awk-way/