LoginSignup
1
2

More than 5 years have passed since last update.

そっか、joinを使えばOKだった

Posted at

探索対象ファイルに対してnkfで文字コード、改行コード情報を取得。
この結果に「拡張子だけ」の列を付け加えたいという事案。

もちろんPythonを使っても良いのですが
ワンライナーでできないかなと探索したら、、、joinコマンドを発見しました。

で、一時ファイルに出力せず標準出力結果を直接joinします。
(一時ファイルに書くとなにかと後処理がめんどいし事故になったりもする。。。)

これぐらいの処理ならDBやPythonまで
ご参加いただく必要はないですね。

join -t, <(find ./popko/ -type f | \
           awk -F"." '{print $0","$NF}' | \
           sort) \
         <(find ./popko/ -type f | \
           xargs nkf --guess | \
           awk -F"[:()]" '{print $1","$2","$3}' | \
           sed -e 's/ //g' | \
           sort)  
結果
./popko/Def.txt,txt,ASCII,LF
./popko/aaa.bbb.ccc,ccc,ASCII,LF
./popko/data.txt,txt,ASCII,LF

1
2
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
2