I am using a bash command, gps location
, that returns a date, time and location information.
[john@hostname :~/develp] $ gps location
Location: {"date": "16/07/20", "time": "19:01:22", "latitude": "34.321", "longitude": "133.453", "altitude": "30m"}
I want to write the longitude to a file, before I get there I need to correctly parse the string.
[john@hostname :~/develp] $ variable=`gps location | awk '/"longitude":/ {print $9}'`
[john@hostname :~/develp] $ echo $variable
"133.453",
[john@hostname :~/develp] $
Currently, awk
isn't searching for longitude, it solely is taking the whole string and finding the 9th string. Ideally, I would like to use a regex/keyword approach and find longitude and then the next string after. I have tried using grep | cut
also tried sed
. No luck, best I can do is using awk
.