17

I have a huge gzipped file and I want a program (4s-import in this case) to read it. It takes a lot of time to first unzip the file and then call the program with the path to the file as an argument. Would it be possible to do something like:

zcat huge.gz | 4s-import <SOME MAGIC>

where SOME-MAGIC is like a path to an abstract file that contains stdin?

The much slower and more disk space consuming alternative that I have to do otherwise is:

zcat huge.gz > huger
4s-import huger
| improve this question | | | | |
33

You can use the process substitution operator <() of bash (or zsh):

4s-import <(zcat huge.gz)

This operator will create a temporary fifo /dev/fd/NN and replace <(.) with the string /dev/fd/NN. 4s-import now can open /dev/fd/NN and read from that fifo, while bash will run zcat huge.gz, which sends its output to /dev/fd/NN.

| improve this answer | | | | |
17
  1. Many programs have a - as standard input. If yours does, use that as it's "builtin".

  2. You can also try using /dev/stdin or /dev/fd/0 as a file.

  3. A third option is to use mkfifo to create a fifo special file. In one shell you pipe in your data (eg. gunzip > your_fifo_file), while in the other you call your program with the fifo as the file.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.