I need to convert an output array to lines without brackets, quotes and commas, so that it can be used to create git clones.
This is my original query
curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?per_page=20 ^
-u user:pass | H:\Downloads\Win64\jq-win64.exe -r "[.values[] | ((.links.clone[] | select(.name==\"http\") | .href) + \" \" + .name)]"
which returns an output of the format
[
"http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository1",
"http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository2"
]
I want to use the output as input to another command like below
curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?per_page=20 ^
-u user:pass | H:\Downloads\Win64\jq-win64.exe -r "[.values[] | ((.links.clone[] | select(.name==\"http\") | .href) + \" \" + .name)]" | ^
H:\Utilities\Git\usr\bin\xargs.exe -n 2 git clone -b release-dev
To be able to use this command, the output of the jq command needs to be like this
http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository1
http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository2
The first part is part of this link
What changes do I need to make to the JQ filter so that I can perform this? In reality I need to clone more than 40 repositories from the BitBucket project and I would like to create a simple script where I do not have to get the list first.
You could simply tack on the following jq filter to the filter that produces the array of two strings:
.[]
Or more economically, simply remove the outer square brackets from the jq query.
The point is that the -r option only strips the double-quotation marks on outputs that are JSON strings (not strings within compound entities).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With