Skip to content

Instantly share code, notes, and snippets.

@sport4minus
Last active January 11, 2022 16:35
Show Gist options
  • Save sport4minus/7628825524954200e65276de85874483 to your computer and use it in GitHub Desktop.
Save sport4minus/7628825524954200e65276de85874483 to your computer and use it in GitHub Desktop.
batch re-encode windows encoded .txt files to UTF-8 on the MacOS command line

Re-encode all .txt files in a directory from windows-1252 to utf-8 in place

  • using find and iconf commands on osx
  • replaces original files!
  • two-step process:
    • first store all paths to text files in a separate file
    • then do conversion based on each file path
    • why? find -exec with iconv was too hard to figure out on macOS

1:

find . -type f -iname "*.txt" > list.ls

2:

cat list.ls | while read line; do cat $line | iconv -f WINDOWS-1252 -t UTF-8 > tmp; mv tmp $line; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment