4
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.

文字コードがShift-JISのファイルを再帰的に抽出する

Posted at

残念ながら、現実はこうなってる。

$ tree
.
├── dir1
│   ├── sjis.txt
│   └── utf8.txt
└── dir2
    ├── dir3
    │   └── sjis.txt
    └── euc.txt

このディレクトリからsjisで書かれたファイルだけ抽出したい。 nkf--guess オプションを使えばできるとは思ってたけど、意外と面倒だった。なんかもっといい方法ある気もする。

$ IFS=$'\n'; for file in `find . -type f`; do nkf --guess "$file" | grep Shift_JIS >/dev/null 2>&1 && echo "$file"; done;
./dir2/dir3/sjis.txt
./dir1/sjis.txt

nkf はコマンドの中でも好きな方。echoのところ例えば nkf -w --overwrite にすれば、SJISをUTF-8にしちゃえる。

4
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
4
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?