LoginSignup
1
0

More than 3 years have passed since last update.

[shell] ディレクトリ内にある画像ファイルをpdfにまとめて{ディレクトリ名}.pdfとして出力する

Posted at

やりたいこと

以下のようにカレントディレクトリの中に複数のディレクトリがあり、
さらにそのディレクトリの中に複数の画像ファイルが格納されています。

ディレクトリ01/
 - picture01-01.jpg
 - picture01-02.jpg 
ディレクトリ02/
 - picture02-01.jpg
 - picture02-02.jpg
ディレクトリ03/
 - picture03-01.jpg
 - picture03-02.jpg
  ...

この状況下で、シェルを実行し、各ディレクトリ内の画像ファイルを1つのpdfにまとめて、
以下のように出力をします。

ディレクトリ01.pdf (picture01-01.jpg + picture01-02.jpg)
ディレクトリ02.pdf (picture02-01.jpg + picture02-02.jpg)
ディレクトリ03.pdf (picture03-01.jpg + picture03-02.jpg)

シェル


PRE_IFS=$IFS; 
IFS=$'\n'; 

for dir in `ls` 
 do 
  convert $dir/*.jpg $dir.pdf
done

これで終わり。

ワンライナー 

これくらいならワンライナーでもいいでしょう。

$ PRE_IFS=$IFS; IFS=$'\n'; for dir in `ls` ; do convert $dir/*.jpg $dir.pdf ; done
1
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
1
0