This command will shorten any URL the user inputs. What makes this command different is that it utilizes 5 different services and gives you 5 different outputs.

curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url"...............
This command will shorten any URL the user inputs. What makes this command different is that it utilizes 5 different services and gives you 5 different outputs: is.gd, bit.ly, u.nu, geekology.co.za, and tinyurl. curl -s http://tinyurl.com/create.php?url=$1 \ | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://bit.ly/?url=$1 \ | sed -n 's/.*\(shortened-url" value="http:\/\/bit.ly\/[a-zA-Z0-9][a-zA-Z0-9]*\).*/\1/p' \ | sed -n 's/.*\(http:\/\/bit.ly\/[a-zA-Z0-9][a-zA-Z0-9]*\).*/\1/p' \ | uniq ; curl -s http://geekology.co.za/shortii/create.php?u=$1 \ | sed -n 's/.*\(http:\/\/geekology.co.za\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://u.nu/unu-api-simple?url=$1 \ | sed -n 's/.*\(http:\/\/u.nu\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq ; curl -s http://is.gd/api.php?longurl=$1 \ | sed -n 's/.*\(http:\/\/is.gd\/[a-z0-9][a-z0-9]*\).*/\1/p' \ | uniq echo ""

0
By: o0110o
2010-01-11 01:11:27

What Others Think

Don't forget to chmod +x filename :)
o0110o · 644 weeks and 6 days ago
I don't understand why you're piping to sed for the services that just return a url. Also, grep's -o|--only-matching option does what you're doing with sed, and in my opinion, is a bit easier to use and understand. For instance: curl -s http://tinyurl.com/create.php?url="$1"|grep -Eo "http://tinyurl.com/[^<'\"\ ]+"|uniq curl -s http://bit.ly/?url="$1" | grep -Po '(?<=-url" value=")[^"]+' curl -s http://geekology.co.za/shortii/create.php?u="$1";echo curl -s http://u.nu/unu-api-simple?url="$1" curl -s http://is.gd/api.php?longurl="$1";echo
eightmillion · 644 weeks and 5 days ago
I tried your example and you're right, Grep is simpler. I used Sed because it was consistent with the examples I studied before trying it for myself. I'm really kind of a noob when it comes to "awesome" commands, lol. I really appreciate your advice and your example, thanks. o0110o http://androidista.com
o0110o · 644 weeks and 4 days ago
No problem. If sed is what you know and it works for you, then you should use sed. Sed, in my experience, also seems to be more consistent across platforms as long as you aren't using any of the GNU specific extensions. Your bit.ly shortener is likely to be more portable. That -P option for grep is really hit and miss.
eightmillion · 644 weeks and 4 days 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: