简体   繁体   English

Linux:zgrep tar.gz 文件中的一行中的多个字符串

[英]Linux: zgrep multiple strings in one line from a tar.gz file

I have a tar.gz file (named as logs.tar.gz) which contains thousands of pieces of information, like this one shown below:我有一个 tar.gz 文件(名为 logs.tar.gz),其中包含数千条信息,如下所示:

2020-06-07 09:02:14.983 {"action":"request","categoryName":"INN","url":"/inn/entryCategory/fetch","loginName":"+441234123456","token":"abcxyz","body":{"approvalType":""}}

I want to zgrep following three pieces of string from the above log sample:我想从上面的日志示例中 zgrep 以下三段字符串:

2020-06-07 09:02:14.983  
/inn/entryCategory/fetch  
+441234123456  

ie IE
1- i want to fetch complete date in this very format, 1-我想以这种格式获取完整的日期,
2- want to fetch the URL 2-想要获取 URL
3- and finally want to fetch the login name which in my case is the phone number. 3-最后想要获取登录名,在我的例子中是电话号码。

I am successful in pulling results one by one.我成功地一一拉出结果。 However i want to zgrep all three strings IN ONE GO.但是我想在一个 GO 中对所有三个字符串进行 zgrep。 (fetch only those results which carry all three pieces of strings) (只获取那些携带所有三个字符串的结果)
Command that i am using is:我正在使用的命令是:

zgrep -a "/inn/entryCategory/fetch" logs.tar.gz  

And if i want to zgrep more than three pieces of strings from one line, what would be the command.如果我想从一行中 zgrep 三个以上的字符串,命令是什么。

Shall be very thankful, if somebody would help.将非常感谢,如果有人会帮助。

if I understand correctly then you can just put .* between each of the pieces of text you want to match and then you will just get lines where all three are present.如果我理解正确,那么您可以将.*放在要匹配的每个文本之间,然后您将得到所有三个都存在的行。

Eg例如

zgrep "2020-06-07 09:02:14.983.*/inn/entryCategory/fetch.*+441234123456 

Is that what you meant?这是你的意思吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM