ディレクトリ内のすべてのテキストファイルを1つのcsvに変換する方法

ディレクトリ内のすべてのテキストファイルを1つのcsvに変換する方法

ディレクトリ内のすべてのテキストファイルをcsvファイルに変換したいと思います。 csvへの入力を、ファイル名のテキストファイル作成者がタグ付けしたテキストファイルのテキストにしたいと思います。ちなみに、一部のファイル名は次のとおりです。

'Winston Churchill___The Crisis, Complete.txt'
'Winston Churchill___The Crossing.txt'
'Winston Churchill___The Dwelling Place of Light, Complete.txt'
'Winston Churchill___The Inside of the Cup, Complete.txt'
'Zane Grey___Betty Zane.txt'
'Zane Grey___Desert Gold.txt'
'Zane Grey___Riders of the Purple Sage.txt'

サンプル出力は次のとおりです。

column1     column2                     
Author1     text written by author 1......   
Author1     text written by author 1......   
Author2     text written by author 2......   
Author2     text written by author 2......              

編集:テストテキスト...対応する列に作成者が作成したテキスト1000文字が必要です。

ベストアンサー1

ksh93代わりに、その形式で印刷をbashサポートする機能が組み込まれているため、より効率的です。csv%#q printf$(<file)

for file in *___*.txt; do
  printf "%#q,%#q\n" "${file%%___*}" "$(<"$file")"
done >> file.csv

おすすめ記事