Created
April 15, 2024 20:55
-
-
Save FranklyFuzzy/fc5a0cb2487ce8d8cd336a2c3698d0e6 to your computer and use it in GitHub Desktop.
Extract IPs from 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
#!/bin/bash | |
# Check if a filename is provided as an argument | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <filename>" | |
exit 1 | |
fi | |
filename="$1" | |
# Read the file line by line | |
while read -r line; do | |
# Modify the regex pattern as needed for your specific use case | |
ip_regex='([0-9]{1,3}\.){3}[0-9]{1,3}' | |
# Extract IPs from the line | |
while [[ "$line" =~ $ip_regex ]]; do | |
ip="${BASH_REMATCH[0]}" | |
#echo "Found IP: $ip" | |
echo $ip | |
line="${line/${BASH_REMATCH[0]}/}" | |
done | |
done < "$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment