Created
December 8, 2020 21:26
-
-
Save rodrigodev/e4dc6d5c654969a7e6492a97603e503b to your computer and use it in GitHub Desktop.
Revisions
-
rodrigodev created this gist
Dec 8, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/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