I have a json file from where I want to get the value of two items which are in an array using grep
. Let's say I'm trying to get data from values foo
and bar
, the problem is that bar
also matches megabar
so I have to grep it with option -w
.
The problem comes when trying to find them at the same time, as I have to grep
for one value OR the other.
From this question, I managed to get a bit closer to what I'm looking for but my result was something like:
grep -E '(foo|-w bar)' file
"foo": "59766",
"foo": "59770",
"foo": "59774",
"foo": "59778",
"foo": "59782",
"foo": "59786",
Any idea on how to do it?
grep
call under all circumstances? – phk May 27 '16 at 12:00foo
and in the next linebar
so I can work with them later – sysfiend May 27 '16 at 12:01jq
orjsonpipe
or use a language (likeperl
orpython
) which has good json-parsing libraries. – cas May 27 '16 at 14:56