How to Correct File Extensions

#!/bin/bash

# sometimes file extensions are not correct, this script will fix that

for line in $1
do
    type=$(file -0 -F" " "$line" | grep -aPo '\0\s*\K\S+')
    mv "$f" "${line%%.*}.${type,,}"
done