1

with this command i get JSON output:

curl -s -H "Accept: application/json" -X GET "http://192.168.253.21:4440/api/20/project/test/executions?authtoken=kH44NoX35bp1zxohgkMtsOIC9H9tw6UI" | jq -r '.|[.executions[] | select(.job.name != null) | select(.job.name|contains("JIRA_Create_Subtask")) ] | sort_by(.id) | reverse | .[0] | [.status, .job.name, ."date-started".date, ."date-ended".date, .job.project]' > /tmp/1.txt

cat /tmp/1.txt
[
  "succeeded",
  "JIRA_Create_Subtask",
  "2018-04-16T10:00:00Z",
  "2018-04-16T10:00:02Z",
  "test"
]

How to get this output in csv format:

"succeeded","JIRA_Create_Subtask","2018-04-16T10:00:00Z","2018-04-16T10:00:02Z","test"

2 Answers 2

5

You can use @csv format in jq:

curl -s -H "Accept: application/json" -X GET "http://192.168.253.21:4440/api/20/project/test/executions?authtoken=kH44NoX35bp1zxohgkMtsOIC9H9tw6UI" |
jq -r '.|[.executions[] |
   select(.job.name != null) |
   select(.job.name|contains("JIRA_Create_Subtask")) ] |
   sort_by(.id) | reverse | .[0] |
   [.status, .job.name, ."date-started".date, ."date-ended".date, .job.project] |
   @csv'
Sign up to request clarification or add additional context in comments.

2 Comments

getting jq: command not found error.
You need to install jq on your system.
0

If you don't have any space or square brackets in your values, you can use tr:

cat 1.txt | tr -d '[]\n '

tr deletes any [, ], cariage return or space characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.