Score:0

How to filter data through awk or grep to get the time only?

cn flag
curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/compute/tagsList? 
api-version=2019-06-04"| 

Through the above command I'm getting out put like below

root@puppetagent-ubuntu1:/home/azureuser# grep -i "shutdown_time" test.txt  |awk '/value/{print}' |jq

[ { "name": "Application_Name", "value": "POC-Exception" }, { "name": "Cost_Center", "value": "1000501541" }, { "name": "Stage", "value": "POC" }, { "name": "shutdown_time", "value": "16:00 [IST]" } ]

So I want to filter where time and time zones are like IST or PST in value but in this where time is not fixed and time zone is not fixed. Please help me.

pLumo avatar
in flag
Please provide us the expected output. Your english is a bit difficult to understand, maybe you can try to fix it a bit, so we can understand correctly.
hariraj avatar
cn flag
Expected output is "16:00" for now but the value will be changing based on system tag.
Score:2
in flag

Use jq:

$ ... | jq -r '.[]|select(.name == "shutdown_time").value'
16:00 [IST]

$ ... | jq -r '.[]|select(.name == "shutdown_time").value' | cut -d' ' -f1
16:00
hariraj avatar
cn flag
How to remove square bracket through the "cut" command if the input is [16:00]?
pLumo avatar
in flag
you don't use the `cut` for it, rahter `sed` or `awk` then.
hr flag
... you could also consider additional filtering inside jq ex. `|split(" ")[0]` in the first case or `|sub("[][]";"";"g")` for the remove brackets case
hariraj avatar
cn flag
Thanks a lot Mr pLumo & Steeldriver for the help above .
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.