Quick Linux Tip #45:
Try: find . -name '*.txt' -exec sh -c 'iconv -f WINDOWS-1252 -t UTF-8 "$1" -o "$1.utf8" && mv "$1.utf8" "$1"' _ {} \;
Info: iconv converts text encodings (-f=from, -t=to). Wrapping in sh -c enables chaining iconv and mv per file. The _ acts as a placeholder for $0 in the subshell.
Examples:
- $ iconv -f UTF-16 -t UTF-8 windows.txt -o linux.txt # Convert single file
- $ iconv -l | grep -i utf # List all supported UTF encodings
- $ dos2unix *.txt # Fix CRLF line endings only
Note: Always test on a backup copy first. Use iconv -l to see all supported charsets. Use dos2unix if you only need to fix line endings (CRLF to LF).
Leave a Reply