0

I am grepping the one API what ever the values is comming I am passing those list values into one file in that file all the values is showing line by line may I know how can I get side by side . May I know is there any command for that .

curl -u admin:xxxx -X GET https://raju.jfrog.io/raju/api/repositories -H "application/json" | grep "key" | grep "raju" | awk '{print $3}'
"ansiraju",
"ansiraju-testing",
"raju-newrepo",
"raju-test",
"rajujlm",
"rajujlm1234",
"rajujlmk",
"rajujlmmn",
"rajujlmmnkm",
"rajujlmm",

May I know how can I get there values side by side like below

"ansiraju", "ansiraju-testing", "raju-newrepo" ..etc like that . Can any one help me on this

oguz ismail
  • 1
  • 16
  • 47
  • 69
msr
  • 37
  • 3

2 Answers2

1

You can try piping the output through tr with arguments like this tr '\n\t' ', '. Here the translation is done by replacing '\n'and '\t' with ',' and ' '.

curl -u admin:xxxx -X GET https://raju.jfrog.io/raju/api/repositories -H "application/json" | grep "key" | grep "raju" | awk '{print $3}' | tr '\n\t' ', '

Reference: Bash: Strip trailing linebreak from output

0

You should use proper tools, but if you can not do that, you can collect all commands in on tool like awk

your command | awk '/key/ && /raju/ {printf "%s",$3} END {print}'

curl -u admin:xxxx -X GET https://raju.jfrog.io/raju/api/repositories -H "application/json" | awk '/key/ && /raju/ {printf "%s",$3} END {print}'
"ansiraju","ansiraju-testing","raju-newrepo",

It will search for both key and raju at the same time print therd field with correct formatting.

Jotne
  • 40,548
  • 12
  • 51
  • 55