1

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.

McFly
  • 27
  • 6

1 Answers1

1

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?

Chris
  • 1,644
  • 1
  • 11
  • 15
  • Sorry, ignore my answer, I think you just want the matching text right? – Chris Jun 07 '20 at 17:23
  • Maybe this question will help if that is the case https://unix.stackexchange.com/q/13466 – Chris Jun 07 '20 at 17:26
  • Thank you for the immediate response I was making two mistakes, MISTAKE 1: I was using single quotes in command like this: zgrep " '2020-06-07 09:02:14.983' .* '/inn/entryCategory/fetch' .* '+441234123456' " MISTAKE2: I was not following the order, for instance i was using this command which didn't work at all JUST BECAUSE the order of the strings was wrong: zgrep "2020-06-07 09:02:14.983.*+441234123456.*/inn/entryCategory/fetch" Thank you so much for the help. A big thumbs up. – McFly Jun 07 '20 at 17:56
  • I am unable to insert a new line (line break) in comments can someone help me with that as well? :) – McFly Jun 07 '20 at 17:56
  • Ah brilliant, so you got the result you are after? That's excellent, good job :-) – Chris Jun 07 '20 at 17:57
  • Yes @Chris, exactly what i needed. Thanks. Can you tell, how to add a line break or a new line in comments? – McFly Jun 07 '20 at 17:58
  • You mean in StackOverflow comments? Ah, not sure on a phone anyway. On a Mac I'd try option enter probably, otherwise there is SO meta for questions about SO. – Chris Jun 07 '20 at 18:27