1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

大量の .csv.gz を解凍して Shift_JIS (CP932) に変換するワンライナー

1
Last updated at Posted at 2021-01-07

たぶん誰も役に立たないワンライナー。

文字コードが UTF-8 な CSV を gzip 圧縮したファイルが大量にあって、これを解凍しつつ Excel で開けるように Shift_JIS に変換したい。

find . -name '*.csv.gz' -exec bash -c 'a=$(echo "$0" | sed -r "s/\.gz$//"); gzcat $0 | nkf -x -s --cp932 > $a; rm -f $0' {} \;
  • Mac だと zcat じゃなくて gzcat を使うというのにハマってしまった 1 (Linux の人は zcat を使って欲しい)
  • find -execxargs みたいなことができるとは知らなかった、これは便利
  • nkf-x オプションを付けないと半角カナが全角カナに変換されてしまう
  1. https://qiita.com/goyachanpuru/items/1efcb0a45266e81aac0e

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?