Add sed command to remove all domains not containing a dot (should get rid of all invalid domains)

This commit is contained in:
columndeeply
2025-08-10 15:15:05 +02:00
parent 65a0727c19
commit d0275f952f

View File

@ -19,6 +19,8 @@ for file in "$@"; do
sed -i -r 's/^([0-9]{1,3}\.){3}[0-9]{1,3} /127.0.0.1 /g' "$file" sed -i -r 's/^([0-9]{1,3}\.){3}[0-9]{1,3} /127.0.0.1 /g' "$file"
## Remove any lines pointing to an IP address, hosts file only works with domains or hostnames ## Remove any lines pointing to an IP address, hosts file only works with domains or hostnames
sed -i -r '/ ([0-9]{1,3}\.){3}[0-9]{1,3}$/d' "$file" sed -i -r '/ ([0-9]{1,3}\.){3}[0-9]{1,3}$/d' "$file"
## Remove any lines that don't have a dot after the 127.0.0.1
sed -i '/127\.0\.0\.1 [^ ]*\.[^ ]*/!d' "$file"
# Remove multiple spaces and return lines (If anybody knows how to do this with sed please let me know) # Remove multiple spaces and return lines (If anybody knows how to do this with sed please let me know)
tr -s ' ' < "$file" | tr -d '\r' > "$file.tmp" tr -s ' ' < "$file" | tr -d '\r' > "$file.tmp"