0

I am using the goo.gl URL shortener to shorten URL's with a curl command. The command is below:

curl https://www.googleapis.com/urlshortener/v1/url \
  -H 'Content-Type: application/json' \
  -d '{"longUrl": "http://www.google.com/"}'

This returns the response is below:

{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/fbsS",
 "longUrl": "http://www.google.com/"
}

Is there a way to use pbcopy to only copy the shortened URL? (http://goo.gl/fbsS)
I am new to posting on StackOverflow, and would appreciate any responses I can get.

1 Answers1

0

Try this:

$ curl ... | grep '"id":' | cut -d\" -f 4 | pbcopy
holygeek
  • 15,653
  • 1
  • 40
  • 50
  • Thank you for your answer, I have seen this kind of command before but I am unsure how to implement this into the script. I'm guessing I wait for the response, and then run?: grep '"id":' | cut -d\" -f 4 | pbcopy – user922618 Sep 01 '11 at 02:04