Created
March 9, 2018 18:55
-
-
Save leodotcloud/c4cbedaabeba0a06956188a04022e9ce to your computer and use it in GitHub Desktop.
Extract just the domain name or IP address from URL string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
get_domain_name() { | |
echo "$1" | awk -F/ '{print $3}' | sed 's/:.*//' | |
} | |
URLS=$(cat <<-END | |
http://1.1.1.1 | |
http://1.1.1.1:8443 | |
https://1.1.1.1 | |
https://1.1.1.1:8443 | |
http://hello-world | |
http://hello-world.com | |
http://sub.hello-world.com | |
http://hello-world:8080 | |
http://hello-world.com:8080 | |
http://sub.hello-world.com:8080 | |
https://hello-word/foo/bar | |
END | |
) | |
for TEST_URL in ${URLS}; do | |
echo "For URL:${TEST_URL}, domain name:$(get_domain_name ${TEST_URL})" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment