Skip to content

Instantly share code, notes, and snippets.

@jhamfler
Last active October 16, 2019 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhamfler/c0599974b84218e4f23e07bb575f7ee7 to your computer and use it in GitHub Desktop.
Save jhamfler/c0599974b84218e4f23e07bb575f7ee7 to your computer and use it in GitHub Desktop.
# IPv4 is inside a String
echo "address is 127.0.0.1 ." | grep -Eo '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
# IPv4 string can only be an IPv4-address
echo "127.0.0.1" | grep -Eo '^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$'
# replace \n with " "
sed ':a;N;$!ba;s/\n/ /g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment