[opensuse] pdftops on multiple files with white spaces in names
Hello: I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory? (For a single file with no white spaces in the name it would be "pdftops infile.ps outfile.pdf".) Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Istvan Gabor said the following on 03/08/2010 12:22 PM:
Hello:
I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory? (For a single file with no white spaces in the name it would be "pdftops infile.ps outfile.pdf".)
Read the BASH (SH) man page. Look under "for" and "list", as in for name in ...list... do .... done Of course there are many (hundreds) of variations using functions, generators and much else, but the solution is ... a shell script :-) Almost all questions that arise here end up with using the shell, so its worth learning even if you are not into system administration. Shell is about the simplest, most straight forward language you can find under Linux. It is also very powerful. But we've told you that before, Istvan. I really do suggest you take the time to learn the shell. It will profit you immensely. -- Faith: Belief without evidence in what is told by one who speaks without knowledge, of things without parallel. --Ambrose Bierce, The Devil's Dictionary -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
2010. március 8. 20:29 napon Anton Aylward <anton.aylward@rogers.com> írta:
Istvan Gabor said the following on 03/08/2010 12:22 PM:
Hello:
I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory? (For a single file with no white spaces in the name it would be "pdftops infile.ps outfile.pdf".)
Read the BASH (SH) man page.
Look under "for" and "list", as in
for name in ...list... do .... done
I do know how to use for loops, I have problem with white spaces in file names. Can $i handle these files? [snip]
Almost all questions that arise here end up with using the shell, so its worth learning even if you are not into system administration.
I absolutely agree with this. [snip] Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Istvan Gabor wrote:
I do know how to use for loops, I have problem with white spaces in file names. Can $i handle these files?
The most important thing is to remember to double quote filenames, like David Bolt and David Haller showed. If you forget that, the shell uses the spaces to break the name into several arguments. If you remember to quote, the shell treats the whole name as one argument. So no, $i can't handle it, but "$i" can handle it. Cheers, Dave -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Dave Howorth said the following on 03/09/2010 06:17 AM:
Istvan Gabor wrote:
I do know how to use for loops, I have problem with white spaces in file names. Can $i handle these files?
The most important thing is to remember to double quote filenames, like David Bolt and David Haller showed. If you forget that, the shell uses the spaces to break the name into several arguments. If you remember to quote, the shell treats the whole name as one argument.
So no, $i can't handle it, but "$i" can handle it.
All of which is documented quite clearly in the MAN page for the shell. -- An ounce of action is worth a ton of theory. - Friedrich Engels -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/03/10 09:19, Istvan Gabor wrote:
2010. március 8. 20:29 napon Anton Aylward <anton.aylward@rogers.com> írta:
Istvan Gabor said the following on 03/08/2010 12:22 PM:
Hello:
I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory? (For a single file with no white spaces in the name it would be "pdftops infile.ps outfile.pdf".)
Read the BASH (SH) man page.
Look under "for" and "list", as in
for name in ...list... do .... done
I do know how to use for loops, I have problem with white spaces in file names. Can $i handle these files?
The ABS comes up often, but it really is very good: http://tldp.org/LDP/abs/html/quoting.html http://tldp.org/LDP/abs/html/loops1.html Specifically make sure you quote the variables correctly and the whitespace will cause no problem. Read some of the examples, and do some quick experimentation, and it'll all seem so simple. for i in *; do pdftops "$i" "${i/%pdf/ps}" done Regards, Tejas -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Mon, 08 Mar 2010, Istvan Gabor wrote:
I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory?
for file in *.ps; do pstopdf "${file}" done IIRC, the "outfile" is optional. You can use it explicitly with: pstopdf "${file}" "${file//.ps/.pdf}" ## requires a POSIX shell, ## e.g. bash, ksh, zsh ... HTH, -dnh -- An American thinks 100 years is a long time; An European thinks 100 miles is a long distance. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 08 March 2010 20:01:20 David Haller wrote:
Hello,
On Mon, 08 Mar 2010, Istvan Gabor wrote:
I would like to convert several ps files to pdf using pdftops. What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory?
for file in *.ps; do pstopdf "${file}" done
IIRC, the "outfile" is optional. You can use it explicitly with:
pstopdf "${file}" "${file//.ps/.pdf}" ## requires a POSIX shell,
That would replace any and all occurrences of ".ps" in a file name with ".pdf" . That may be okay if there is only one occurrence but, to make sure that only the extender is replaced, this would be a better choice: pstopdf "${file}" "${file%.ps}.pdf" Regards, David Bolt -- Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s openSUSE 11.0 32b | | | openSUSE 11.3M3 32b openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b | TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
2010. március 8. 21:11 napon David Bolt <bcrafhfr@davjam.org> írta: [snip]
What would be the correct command line for batch processing if the ps filenames have white spaces and I have many files in the same directory?
for file in *.ps; do pstopdf "${file}" done
IIRC, the "outfile" is optional. You can use it explicitly with:
pstopdf "${file}" "${file//.ps/.pdf}" ## requires a POSIX shell,
That would replace any and all occurrences of ".ps" in a file name with ".pdf" . That may be okay if there is only one occurrence but, to make sure that only the extender is replaced, this would be a better choice:
pstopdf "${file}" "${file%.ps}.pdf"
Thanks, I did know about the for loop but I did not know that I can use quote signs to protect white spaces. Thanks again, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Mon, 08 Mar 2010, David Bolt wrote:
On Monday 08 March 2010 20:01:20 David Haller wrote:
IIRC, the "outfile" is optional. You can use it explicitly with:
pstopdf "${file}" "${file//.ps/.pdf}" ## requires a POSIX shell,
That would replace any and all occurrences of ".ps" in a file name with ".pdf" . That may be okay if there is only one occurrence but, to make sure that only the extender is replaced, this would be a better choice:
Darn. Too used to sane filenames.
pstopdf "${file}" "${file%.ps}.pdf"
Alternatively: pstopdf "${file}" "${file//%.ps/.pdf}" Thanks, -dnh -- Make sure that they know you know that they know you know. -- Mike Andrews on getting license keys by mail (from a certain Corp.) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Istvan Gabor wrote:
Hello:
I would like to convert several ps files to pdf using pdftops.
Impossible. pdftops does not do that. Pick one or the other: find ./ -name '*.pdf' -maxdepth 1 -exec pdftops '{}' \; or find ./ -name '*.ps' -maxdepth 1 -exec ps2pdf '{}' \; Remove the maxdepth and it will recurse through all subdirectories as well as the current dir. Since you are telling find itself to run the converter util, you don't have to do anything special about the file names. find handles them safely internally, and so do both converter utils, so you're done, as long as you're ok with output files that are the same as the input files with the extension changed. Both utils will do that automatically if you simply omit any destination filename, which is what makes nice short & sweet commands like above possible. However, the single-quotes are important everywhere they appear here, fir different reasons. The single-quotes around "*.foo" are really to prevent the shell from expanding the globbing pattern right there in the command before even handing the result to "find". Preventing that expansion does happen to also prevent any spaces from appearing in the argument, but the point was really to prevent the expansion from creating a huge file list all in the command line, which would exceed the max argument list size for large numbers of files, but since find will interpret the globbing pattern itsef internally, this way works for any number of files from 0 to infinity. The single-quotes around "{}" are also to prevent the shell from interpreting "{...}" the way it normally would, which has nothing to do with spaces or with globbing expansion. (groups commands into a sort of a subroutine) -- bkw -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Anton Aylward
-
Brian K. White
-
Dave Howorth
-
David Bolt
-
David Haller
-
Istvan Gabor
-
Tejas Guruswamy