pbcopy Specific Part of Shell Script

258 Views Asked by At

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

There are 1 best solutions below

1
On

Try this:

$ curl ... | grep '"id":' | cut -d\" -f 4 | pbcopy