#!/bin/bash #enter input encoding here FROM_ENCODING="ISO_8859-1" #output encoding(UTF-8) TO_ENCODING="UTF-8" #convert CONVERT="iconv -f $FROM_ENCODING -t $TO_ENCODING" #loop to convert multiple files for file in ./*.txt; do encoding=$(file -I "$file" | awk '{print $3}') if [ "$encoding" == "charset=iso-8859-1" ]; then $CONVERT "$file" >"$file.new" && mv -f "$file.new" "$file" fi done exit 0