Skip to content

Instantly share code, notes, and snippets.

@ubnt-intrepid
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save ubnt-intrepid/07169f102c3531fa62f6 to your computer and use it in GitHub Desktop.

Select an option

Save ubnt-intrepid/07169f102c3531fa62f6 to your computer and use it in GitHub Desktop.
Shift-JIS から UTF-8 (with BOM) に変換するスクリプト (perl, shell script)
perl -MEncode -pe 'BEGIN{print "\xEF\xBB\xBF"} s/\r\n/\n/g;Encode::from_to($_,"shiftjis","utf-8");' $1 > $2
$ # リポジトリに登録されているファイルから改行コードにCRLFが含まれているものを取り出す
$ git grep --cached --full-name --name-only -I $'\r'
path/to/hoge.txt
path/huga.txt
...
$ # filelist内に記されたファイルの改行コードをCRLF->LFに変換
$ cat filelist | while read line; do perl -i -pe 's/\r\n/\n/g;' "$file"; done
$ cat input.txt
aaaa
あああ
いいい

$ file input.txt
input.txt: Non-ISO extended-ASCII text, with CRLF line terminators
$ ./dos2unix.sh input.txt output.txt
$ file output.txt
output.txt: UTF-8 (with BOM) text
@ubnt-intrepid
Copy link
Author

  • clang-format
  • auto crlf false

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