Skip to content

Instantly share code, notes, and snippets.

@daformat
Last active January 3, 2017 10:54
Show Gist options
  • Save daformat/d146a148d6296501cc13 to your computer and use it in GitHub Desktop.
Save daformat/d146a148d6296501cc13 to your computer and use it in GitHub Desktop.
Extract any url found in input URL (the shell-noob way)
#!/bin/zsh
echo "Url to extract values from:";
read TMPCURLURL;
RESULT=`curl -L $TMPCURLURL`;
# Extract urls within double quotes
echo $RESULT | grep -oE "\"http://.*\"" | cut -d " " -f1 | cut -d '"' -f2;
# Extract urls within single quotes
echo $RESULT | grep -oE "'http://.*'" | cut -d " " -f1 | cut -d "'" -f2
@daformat
Copy link
Author

daformat commented Oct 6, 2014

Reminder: if you paste this directly in your terminal, check that the interactive_comments is enabled (set -k)

Alternatively, here's the one-liner version of the above script without any commments:

echo "Url to extract values from:";read TMPCURLURL; RESULT=`curl -L $TMPCURLURL`; echo $RESULT | grep -oE "\"http://.*\"" | cut -d " " -f1 | cut -d '"' -f2; echo $RESULT | grep -oE "'http://.*'" | cut -d " " -f1 | cut -d "'" -f2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment