resolve short urls

resolve(){ curl -Is $1 | egrep "Location" | sed "s/Location: \(.*\)/\1/g"; }
since the most url shorteners respond with a header containing the Location: ... this works with most common shorteners
Sample Output
resolve http://goo.gl/gy8n
-> http://www.commandlinefu.com/commands/browse

2
By: hoodie
2011-12-06 12:37:46

What Others Think

Use sed?s -n option and 'p' to only print the line of interest; find lines starting with 'Location: ' rather than containing it; no need to store the rest of the line. resolve(){ curl -Is $1 | sed -n 's/^Location: //p'; } Less characters and less commands :)
penpen · 503 weeks and 6 days ago
Seems as if typographic characters are an issue, sorry about that :)
penpen · 503 weeks and 6 days ago
Nevada is a state in the Western United States. It is bordered by Oregon to the northwest, Idaho to the northeast, California to the west, Arizona to the southeast, and Utah to the east. Nevada is the 7th most extensive, the 32nd most populous, but the 9th least densely populated of the U.S. states. MaxRemind Inc top rank medical billing company of USA offers medical billing services in Nevada, medical credentialing services along with home health agency software for home healthcare companies companies in Nevada USA.
stevematt · 27 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: