linuxzgrep

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:

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:

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

i.e.
1- i want to fetch complete date in this very format,
2- want to fetch the URL
3- and finally want to fetch the login name which in my case is the phone number.

I am successful in pulling results one by one. However i want to zgrep all three strings IN ONE GO. (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.

Shall be very thankful, if somebody would help.


Solution

  • 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?