[英]using Zgrep and awk to parse a .tgz file and print first row
I would like to use Zgrep and Awk to print specific lines.我想使用 Zgrep 和 Awk 来打印特定的行。
I use the below script.我使用下面的脚本。 However, I am not able to print the specific line requirement.但是,我无法打印特定的行要求。
zcat SYS.20210519.tgz | zcat SYS.20210519.tgz | awk '/11055/ && /2.5.5.5/' awk '/11055/ && /2.5.5.5/'
It would be nice if someone could help.如果有人可以提供帮助,那就太好了。 Thanks.谢谢。
File name: SYS.20210519.tgz文件名:SYS.20210519.tgz
File INPUT:文件输入:
20210519 072532 11055 ERROR Connection is not writable, error[grpId[2.5.5.5/49.3.14.13:17126] connId[142706130] testMode[true] connInfo[ConnInfo[connId=142706130, connGrp=2.5.5.5/49.3.14.13:17126,
File output (Needed):文件 output(需要):
20210519 072532 11055 ERROR Connection is not writable, error[grpId[2.5.5.5/49.3.14.13:17126]
With your shown samples, could you please try following.使用您显示的示例,您能否尝试以下操作。 Using zcat
to read your Input_file then sending its output as standard input to awk
program.使用zcat
读取您的 Input_file,然后将其 output 作为标准输入发送到awk
程序。 Where using match
function to match regex, which will print till value of error[grpId till ]
occurrence.在使用match
function 匹配正则表达式的地方,它将打印直到 error[grpId until ]
出现的值。
zcat Input_file |
awk 'match($0,/.*error\[grpId\[[^]]*\]/){print substr($0,RSTART,RLENGTH)}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.