Skip to content

Instantly share code, notes, and snippets.

@iegik
Created July 13, 2015 16:03
Show Gist options
  • Select an option

  • Save iegik/be31c339d1a109d79d19 to your computer and use it in GitHub Desktop.

Select an option

Save iegik/be31c339d1a109d79d19 to your computer and use it in GitHub Desktop.
Converts original charset of the file to UTF-8
#!/bin/sh
# Converts original charset of the file to UTF-8
# require iconv, tr, grep | sed | awk
# grep wins: https://davidlyness.com/post/the-functional-and-performance-differences-of-sed-awk-and-other-unix-parsing-utilities
# grep -oe'[^=]*$'
# sed 's/[^=]*[=]//g'
# awk -F= '{print$2}'
for arg in "$@"; do
TMP=".${arg##*/}.$$";
iconv -f `file -bi $arg | grep -oe'[^=]*$'` -t UTF-8 $arg | tr -d '\r' > $TMP
mv $TMP $arg;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment