This script will remove all comments (#, //) and empty lines from a file.

Get file:

$ wget https://bytesofprogress.net/resources/bash-tools/remove-comments/remove-comments.sh

Contents of file:

#!/bin/bash

INPUTFILE="input.txt"
OUTPUTFILE="output.txt"
    # Does the file exist?
if [ ! -f "$INPUTFILE" ]; then
    echo "ERROR: File $INPUTFILE does not exist!"
    exit 1
fi
    # Removing all comments & empty lines.
sed 's/#.*$//' "$INPUTFILE" | grep -v '^[[:space:]]*$' > "$OUTPUTFILE"
    # Show line count before and after.
echo "Output saved as: $OUTPUTFILE"
echo "Original: $(wc -l < "$INPUTFILE") lines | Cleaned: $(wc -l < "$OUTPUTFILE") Lines."