No Such Blog or Diary
pdf のページ数を確認するワンライナー
- 2022-02-04 (Fri)
- 一般 ソフトウェア ( Linux/coLinux )
ls *.pdf | python3 -c 'import PyPDF2;import sys;[print("{} {}".format(PyPDF2.PdfFileReader(open(file.strip(), mode="rb")).getNumPages(),file.strip())) for file in sys.stdin.readlines()]'
しばしばお世話になる pdftools の使ってる PyPDF2 ライブラリを呼ぶ感じでテキトウに.とりあえず動けばいい.
追記:PdfFileReader が Obsolete ということで,PdfReader を使って書き換え:
ls *.pdf | python3 -c 'import PyPDF2;import sys;[print("{} {}".format(len(PyPDF2.PdfReader(open(file.strip(), mode="rb")).pages),file.strip())) for file in sys.stdin.readlines()]'
- Comments: 0
- TrackBack (Close): -
どうにもならん
- 2022-02-02 (Wed)
- 一般
「期末試験ぶっちしたからどうにかしてくれ」って来るのはどうにかならんのか? しかも「出席足りないと期末試験の受験資格なし」という規則があるのに出席足りてねぇとか……
- Comments: 0
- TrackBack (Close): -
read コマンドを少しまともに使う
- 2022-01-30 (Sun)
- 一般 ソフトウェア ( Linux/coLinux )
タブ区切りのフィールドを,タブ以外はそのままに読み込んで flds という配列に入れてもらう:
while IFS=$'\t' read -a flds; do echo ${flds[0]}; ...; done
IFS をちゃんと指定しておかないと空白まで消えちゃうので注意なのと,-a オプションで配列に入れてもらえるので便利なのと.ここらは今までちゃんと使えていなかったのでメモ.
- Comments: 0
- TrackBack (Close): -
