Skip to content

Instantly share code, notes, and snippets.

@kekru
Created July 14, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kekru/aa6db9b27b44f02bf0561a2475764f69 to your computer and use it in GitHub Desktop.
Save kekru/aa6db9b27b44f02bf0561a2475764f69 to your computer and use it in GitHub Desktop.
Convert all files of a dir to UTF8

Convert files of a dir to UTF8

Run this script on linux.
Modify the "find" call and the source encoding.
The example will match all .java files in the current folder and its subfolders and converts from Cp1252 (Windows) to UTF-8.

#!/bin/bash

# modify this find call for your needs
list=$(find . -type f -name "*.java")

for item in $list
do
        echo "Item: $item"

        # change source and target encoding here
        iconv -f Cp1252 -t UTF-8 $item > ${item}.x
        cp ${item}.x ${item}
        rm ${item}.x
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment