if (INPUT)
  if (OUTPUT)
    file(READ "${INPUT}" in0)
# replace carriage returns with a semi-colon
    string (REGEX REPLACE "\n" ";" in0 "${in0}")
    set(out "")
    foreach (l in ${in0})
      # Only retain lines that start with "#"
      set(found "")
      string(REGEX MATCH "^#" found "${l}")
      if (found)
        set(out "${out}${l}\n")
      endif ()  
    endforeach ()
    file(WRITE "${OUTPUT}" "${out}")
  else (OUTPUT)
    message(ERROR "OUTPUT variable must be set")
  endif (OUTPUT)
else (INPUT)
  message(ERROR "INPUT variable must be set")
endif (INPUT)
