Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get URL of top Google result for a query
api=http://ajax.googleapis.com/ajax/services/search/web?v=1.0
url=$(curl -s --get --data-urlencode "q=$1" $api |
sed 's|"unescapedUrl":"\([^"]*\).*|\1|;s|.*GwebSearch",||')
echo -n $url | pbcopy
echo $url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment