0

How may I use zgrep to search for A where B is missing.

Like:

-v This option is used to display the lines which doesn’t have the expression present in it.

tried:
zgrep "search_for_this" | zgrep -v "where_this_is_missing file.json.gz

didn't work. What I need is:

{
  "name": "name",
  "lastname": "lastnameee",
  "nickname: "somenickname"
},
{
  "name": "name",
  "lastname": "lastnameee",
  "nickname: "somenickname"
  "uniqueId": "1028hasidhad89h1hd"
},

I have some files.json.gz and I want to search for lines where: - name exists && uniqueId doesn't. Not just skip the value from the returned result, but to ONLY return those lines where those two conditions are met.

1 Answers1

1
  1. what you want is a json parser like jq. the method you are using only works for that one case where one object e.g. {"name":...} is in exactly one line, so your file would need to look like this:
{"name": "name", "lastname": "lastnameee", "nickname": "somenickname"},
{ "name": "name", "lastname": "lastnameee", "nickname": "somenickname", "uniqueId": "1028hasidhad89h1hd"},
  1. you need to understand what the pipe actually does. the pipe char takes the stdout of one program and passes it to the stdin of another. so you would need to do zgrep "searchstring" file.json.gz | zgrep -v "antisearchstring". you are taking file.json.gz as the input file for the first zgrep, and piping the results into the second zgrep
Malik
  • 325
  • 1
  • 9