From the pdftotext
man page:
If text-file is ´-', the text is sent to stdout.
So in this case all you need is:
pdftotext "C BY BRIAN W KERNIGHAN & DENNIS M RITCHIE.pdf" -
Or if you want to pipe this to STDIN of another program:
pdftotext "C BY BRIAN W KERNIGHAN & DENNIS M RITCHIE.pdf" - | another_prog
Using -
as substitute for a filename is a convention many utilities follow (including pdftotext) when we want input from STDIN or output to STDOUT. However not all utilities follow this convention. In that case the idiomatic way to do this in bash is to use a process substitution:
my_utility "C BY BRIAN W KERNIGHAN & DENNIS M RITCHIE.pdf" >( cat )
Here the >( )
behaves largely like a file passed to my_utility
, but instead of being a real file, the stream is piped into the stdin of the contained process, i.e. cat. So here, the text should ultimately output as required.
Use of cat
almost always sets off UUOC alarm bells on forums like this. I contend that if the utility does not support -
, then this is a useful use of cat
, though if there are any ways to do this process substitution without the cat
, then I'm all ears ;-).
However, if (as the question states) the ultimate destination of of the stream is STDIN of another program, then the cat
can be eliminated:
my_utility "C BY BRIAN W KERNIGHAN & DENNIS M RITCHIE.pdf" >( another_prog )
cat <file | cmd /dev/fd/0
works on most unices.cat < README.txt | cp /dev/fd/0
. It saidcp: missing destination file operand after ‘/dev/fd/0’ Try 'cp --help' for more information.
program input-file /dev/stdout | another-program
? Also note thatecho
reads nothing from stdin.cp
a file nowhere.echo 1 2 3| cp /dev/fd/0 /dev/tty
will print1 2 3
. And by the way,/dev/fd/[num]
is more likely to work than/dev/std(in|out|err)
in most cases. See Portability of File-Descriptor Links about what you can expect to work where.