'Get the values which are created in last few minutes from a Json file
My Json file has the data like below:
[
{
"id": 47,
"iid": 12,
"project_id": 1,
"status": "pending",
"source": "push",
"ref": "new-pipeline",
"sha": "ab23456789d",
"web_url": "https://example.com/project/pipelines/47",
"created_at": "2022-02-24T11:28:34.085Z",
"updated_at": "2016-08-24T15:32:35.169Z"
},
{
"id": 48,
"iid": 13,
"project_id": 1,
"status": "pending",
"source": "web",
"ref": "new-pipeline",
"sha": "ab23456789d",
"web_url": "https://example.com/project/pipelines/48",
"created_at": "2022-02-23T11:28:34.085Z",
"updated_at": "2016-08-23T15:32:35.169Z"
}
]
I am trying to fetch the IDs which are created in last 15 minutes. But I couldnt get it.
I have tried the below way,
TIM=`date -u +"%Y-%m-%dT%H:%M:%S.000Z" -d '-15 minutes'`
jq -r --arg TIMEE "$TIM" '.[]|select((.ref|contains("dev")) and (.updated_at >= "$TIMEE"))|.id' MyJsonFile.json
But this is not working as expected. I dont see any IDs. But when made the condition to (.updated_at >= "$TIMEE"). I can see all IDs which are created even in last one minute.
Not sure if I am trying in the right way. Any help is much appreciated.
Solution 1:[1]
TIM=`date -u +"%Y-%m-%dT%H:%M:%S.000Z" -d '-15 minutes'`
jq -r --arg TIMEE "$TIM" '.[]|select((.ref|contains("dev")) and (.updated_at >= $TIMEE))|.id' MyJsonFile.json
just removing the quote around "$TIMEE" will work. It might be taken as a string if you quote it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
