I don't know if that's the proper title for my question. Please pardon me with that.
The code that I've tried is not getting the exact output that I want. This is my code that I've tried:
curl -s --request GET \
http://10.10.5.242/api/v1/incidents \
-H "Content-Type: application/json;" \
-H "X-Cachet-Token: ROvbssneyYwR8fwNgOWj" \
| json_pp | grep -e id -e component_id
And it will output this
"component_id" : "4",
"id" : 1,
"id" : 2,
"component_id" : "4",
"id" : 3,
"component_id" : "4",
"component_id" : "4",
"id" : 4
"component_id" : "3",
"id" : 5,
"component_id" : "2",
"id" : 6,
This is the content of the api the I'm using http://10.10.5.242/api/v1/incidents
{
"meta": {
"pagination": {
"total": 6,
"count": 6,
"per_page": 20,
"current_page": 1,
"total_pages": 1,
"links": {
"next_page": null,
"previous_page": null
}
}
},
"data": [
{
"id": 1,
"component_id": "4",
"name": "Service Unavailable",
"status": "4",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-23 14:56:16",
"updated_at": "2018-02-26 08:37:11",
"deleted_at": null,
"human_status": "Fixed"
},
{
"id": 2,
"component_id": "4",
"name": "Service Unavailable",
"status": "4",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-23 15:39:52",
"updated_at": "2018-02-26 08:37:11",
"deleted_at": null,
"human_status": "Fixed"
},
{
"id": 3,
"component_id": "4",
"name": "Service Unavailable",
"status": "4",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-26 08:15:43",
"updated_at": "2018-02-26 08:37:12",
"deleted_at": null,
"human_status": "Fixed"
},
{
"id": 4,
"component_id": "4",
"name": "Service Unavailable",
"status": "4",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-26 08:19:12",
"updated_at": "2018-02-26 08:37:12",
"deleted_at": null,
"human_status": "Fixed"
},
{
"id": 5,
"component_id": "3",
"name": "Service Unavailable",
"status": "2",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-26 10:01:32",
"updated_at": "2018-02-26 10:01:32",
"deleted_at": null,
"human_status": "Identified"
},
{
"id": 6,
"component_id": "2",
"name": "Service Unavailable",
"status": "2",
"visible": 1,
"message": "Server is not responding",
"scheduled_at": "2018-02-26 10:05:03",
"created_at": "2018-02-26 10:03:38",
"updated_at": "2018-02-26 10:03:38",
"deleted_at": null,
"human_status": "Identified"
}
]
}
The output that I want is to get all the id of "component_id": "4", and will output this
"id" : 1,
"id" : 2,
"id" : 3,
"id" : 4,
What I've wanted is grep the component_id and will get the all of the values of id of component id. Cause my plan is to bring those values in my for loop.