我试图创build一个bash脚本,将使用egrep grep从一个文件的行。 我已经创build了应该将我想要的信息分组的正则expression式,问题是试图获得输出。 我一直在用下面的命令testing它,但是运行时没有打印任何东西。 如何打印 – {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这样的工具。
awk '/^----+$/ {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/
只是因为我最终完成了一个sed版本
sed -n '/^-----\+$/,/^Disonnected/ {/^----\+$/d;/^Disonnected/d;p;}' testing.txt
这将在/ RE1 /和/ RE2 /之间的所有行上进行操作,如果input与/ RE1 /或/ RE2 /匹配,则删除它,否则将打印。