0
0

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 3 years have passed since last update.

複数のPDFファイルの文字列を一つのテキストファイルにまとめる

Last updated at Posted at 2021-08-03
concat.zsh
# !/usr/bin/zsh
for i (**/*.pdf) pdftotext -layout -nopgbrk "${i}" - >> OUT.txt
  • for i (**/*.pdf) はこのディレクトリ以下のすべてのpdfファイルを列挙して変数$iに格納する。
  • pdftotextはPDFファイルのテキストを抽出してファイルまたはSTDOUTに出力するコマンド。お使いのパッケージマネージャーでpopplerとかpoppler-utilをインストールしてください。
  • -layout -nopgbrkpdftotextのオプションで、レイアウトを読みやすくするためのインデントとページ改行削除の設定
  • ${i} にはすべてのpdfファイル名が相対パスで入る。ダブルクオーテーションと{}を入れないとスペースをコマンド区切りのスペースと認識してしまう
  • -pdftotextの結果を標準出力へ吐き出す。

pdftotextの標準的な使い方は、第二引数に出力ファイル名を指定する。

  • >> OUT.txt でtxtファイルへ標準出力を追記していく。
  • zsh専用

bash用はbashで仕事したいあなたがこの記事を編集してくれる

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?