Grep wildcard in middle of string -


ok problem having have file contains numerous lines this.

{"cameraendpoint":"your.url.here","cameraid":"20mp s middle port 2","warehouseid":"random"}

thig need actual cameraid have tried grep fu no luck here 1 of commands ran.

grep -o '\"cameraid\":\"*"' camlist.txt 

but returns

"cameraid":" "cameraid":" "cameraid":" "cameraid":" "cameraid":" "cameraid":" "cameraid":" "cameraid":"

where need data between quotations.

if understand properly, want attribute of cameraid, in example being 20mp s middle port 2.

if so, can this:

$ grep -po '(?<=cameraid":")[^"]*' file 20mp s middle port 2 

it fetchs data after cameraid":" till next ".

test

$ cat file {"cameraendpoint":"your.url.here","cameraid":"20mp s middle port 2","warehouseid":"random"} {"cameraendpoint":"your.url.here","cameraid":"hello s middle port 2","warehouseid":"random"} {"cameraendpoint":"your.url.here","camaid":"hello s middle port 2","warehouseid":"random"} $ grep -po '(?<=cameraid":")[^"]*' file 20mp s middle port 2 hello s middle port 2 

Comments