3
4

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.

Macで複数のPDFの合計文字数を数える方法

Posted at

大量のPDFの文字数を一気に数えたい

 PDFの文字数を数えたときのメモです。

 流れとしては以下となります。

事前準備

 popplerというパッケージソフトをインストール

 Homebrewを使えば以下コマンドでOKです。

$ brew install poppler

文字数カウント方法

手順

 手順は以下となります。

  • popplerの中のpdftotextというソフトでpdfをテキストファイルに変換
  • catコマンドでテキストファイルを1つのファイルにまとめる
  • テキストファイルの文字数を数える

 スクリプトにまとめたので、pdfファイルが入ったフォルダで以下2行を実行すればOKです。

$ wget https://raw.githubusercontent.com/karaage0703/scripts/master/wordcount_all_pdf.sh
$ bash wordcount_all_pdf.sh

シェルスクリプトの中身

 中身は以下となっています。

# !/bin/bash
for f in *.pdf
do
    echo $f
    pdftotext $f
done

cat *.txt > all.txt
wc -m all.txt

 もっと良い感じの書き方あれば教えてください。

まとめ

 MacでのPDF文字数の数え方を簡単にまとめました。最近、本を執筆したので、その文字数を数えたくなり調べたものです。

 ちなみに文字数は約26万字(257837)でした。一般的な書籍は10万字程度と聞いていたので、かなり多いですね。技術書なので、プログラムのコードが多いためかもしれません。もしくは、うまく数えられていないのかも…

 ちなみに、書籍は以下となります(宣伝です)。AI初心者向けの本となります。興味ある方はよろしければ。

AIの初心者向けの独学本「からあげ先生のとにかく楽しいAI自作教室」を執筆しました

参考サイト

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?