This script removes lines with "0.0.0.0" or "127.0.0.1" at the beginning of the line. Useful for DNS-Blocklists.
Get file:
$ wget https://bytesofprogress.net/resources/bash-tools/cleanup/cleanup.sh
Contents of file:
#!/bin/bash
INPUTFILE="input.txt"
OUTPUTFILE="output.txt"
# Does file exist?
if [ ! -f "$INPUTFILE" ]; then
echo "ERROR: File $INPUTFILE does not exist!"
exit 1
fi
# Removes lines with "0.0.0.0" or "127.0.0.1" at the beginning of the line.
sed -E 's/^(0.0.0.0|127.0.0.1)[[:space:]]+//g' "$INPUTFILE" | sort -u > "$OUTPUTFILE"
# Show line count before and after.
echo "Output saved as: $OUTPUTFILE"
echo "Original: $(wc -l < "$INPUTFILE") lines | Cleaned: $(wc -l < "$OUTPUTFILE") Lines."