Answer the question
In order to leave comments, you need to log in
How to find a line in a text file using grep?
Good afternoon. I wondered how to use grep on MAC OS. The question is this: there is a text file with many entries of the form:
"id": "5644561-46484-546545" , "number": "879876-5644561-546545" ,"reestr":"46878-6214-8794"
5644561-46484-546545: 46878-6214-8794
grep'\"id\":\"{}\"'|grep '\"reestr\":\"[0-9]*' > result.txt
Answer the question
In order to leave comments, you need to log in
For handling json documents IMHO it's better to use jq .
It has advanced features for filtering and searching by json, it is perfectly installed on a poppy through homebrew.
I wondered how to use grep on MAC OS.
tr -d '[:space:]"' | awk -F',' '{print $1 $3}' | sed -e 's/id://' -e 's/reestr:/: /'
Yes, json search
[
{"id": "5644561-46484-546545" , "number": "879876-5644561-546545" ,"reestr":"46878-6214-8794"},
{"id": "6644561-46484-546545" , "number": "979876-5644561-546545" ,"reestr":"56878-6214-8794"},
{"id": "7644561-46484-546545" , "number": "079876-5644561-546545" ,"reestr":"66878-6214-8794"}
]
$ jq -r '.[] | "\(.id): \(.reestr)"' file.json
5644561-46484-546545: 46878-6214-8794
6644561-46484-546545: 56878-6214-8794
7644561-46484-546545: 66878-6214-8794
$ jq -r '.[] | select(.id == "7644561-46484-546545") | "\(.id): \(.reestr)"' file.json
7644561-46484-546545: 66878-6214-8794
$ jq -r --arg ID "7644561-46484-546545" '.[] | select(.id == $ID) | "\(.id): \(.reestr)"' file.json
7644561-46484-546545: 66878-6214-8794
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question