Created
May 9, 2020 13:07
-
-
Save f9n/cf2f8f8a9edb52c7a21481f6fc5e13d9 to your computer and use it in GitHub Desktop.
Get all ip addresses on file
This file contains 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
#!/usr/bin/env bash | |
# Credits | |
# https://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell | |
file=$1 | |
seperator=${2:-'\n'} | |
result=$(grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' $file) | |
for ip in $result; do | |
echo -e "${ip}$seperator\c" | |
done | |
echo | |
### Usage | |
# $ sezen <file> [seperator] | |
# $ sezen dirty-file.txt | |
# 10.250.200.1 | |
# 10.250.200.2 | |
# $ sezen dirty-file.txt ',' | |
# 10.250.200.1,10.250.200.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
candan.sh
Usage