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.

pdftotext コマンド+ファイル名表示(シェルスクリプト )

Last updated at Posted at 2021-06-13

こんにちは
pdftotextコマンドをfindと組み合わせて使うことにし、シェルスクリプトに仕立てました。ファイル名が行頭に表示されるようにしました。

$ find . -name "*.pdf" -print0 | xargs -0 ./pdftotext.sh
./1.pdf: ...
./1.pdf: ...
./2.pdf: ...
 :
 :
pdftotext.sh
# !/bin/sh
options=""
while [ $# -gt 0 ]; do
  case "$1" in
    -*)       options="$options $1"; shift ;;
    *)        break ;;
  esac
done

for file in "$@"; do
  [ "${file##*.}" != "pdf" ] && continue
  pdftotext $options "$file" - | while read -r line; do printf '%s\n' "$file: $line"; done
done
exit
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?