LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-10-2005, 04:08 PM   #1
juergenkemeter
LQ Newbie
 
Registered: Oct 2005
Posts: 2

Rep: Reputation: 0
bash script for converting ps to pdf


Hi!
I have a folder with many subfolders. Each of these subfolders contain several Postscript (.ps) - files. Now I want to convert the ps-files in all of these folders into pdf format, doing so with a Bash Shell Script.

This is what I got so far:
Code:
#! /bin/bash

echo `pwd`
DIR=`pwd`/Desktop/MFold_Output

cd $DIR
echo `pwd`

#ls -l $DIR
#echo $DIR

for dir in `ls`
do
    echo $dir;
    cd $dir
    echo `pwd`
    for file in `ls *.ps`
    do
	echo $file;
	
    done
cd ..
done
The parent folder is 'MFold_Output'. in the first for-loop, I go into this parent folder and list all subfolders. The second for-loop enteres each subfolder and lists its containing ps - files.
The Script is working so far.
My problem is how to actually convert the ps to pdf, eventuallly using xargs. It would also be good if the ps files wouln't be deleted.

Cheers,
Jurgen
 
Old 10-10-2005, 04:45 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Couldn't you just use find?
find /path/to/base/dir -name "*.ps" -exec ps2pdf "{}" "{}.pdf" \;
 
Old 10-10-2005, 05:06 PM   #3
tboerner
LQ Newbie
 
Registered: Sep 2005
Posts: 4

Rep: Reputation: 0
Hi Juergen,

what do you think about the following:

for ps in $(find . -name "*.ps");do
pdf="$(dirname "$ps")/$(basename "$ps" .ps).pdf"
ps2pdf "$ps" "$pdf"
done

Please try and let us know.

Cheers
TB
 
Old 10-10-2005, 05:35 PM   #4
juergenkemeter
LQ Newbie
 
Registered: Oct 2005
Posts: 2

Original Poster
Rep: Reputation: 0
thx

Hi all,
thanks for your answers. There are many ways to do this.
I found a solution today, using a regular expression:
Code:
    do
	file=${file//\.ps/}
#	echo $file
	ps2pdf ${file}.ps ${file}.pdf
    done
Jurgen
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting extended ascii (,) in bash script Hko Programming 4 12-29-2012 04:42 AM
Converting pdf to Html linuxeagle Linux - General 1 04-23-2004 09:03 AM
Converting html files to pdf saurya_s Linux - Software 1 01-12-2004 07:49 AM
converting documents to pdf Chijtska Linux - General 5 02-05-2002 06:30 PM
converting files to pdf format? vendemmian Linux - General 2 05-23-2001 08:52 AM


All times are GMT -5. The time now is 10:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration