0
votes

Suppose I have the following file:

0 a b c
1 1 2 2
2 4 4 2
3 8 6 2

And I want to send it from the command line:

cat foofile | gnuplot -e 'file="/dev/stdin"' plot.p

With the following plotfile:

set key outside
plot for [col=2:4] file using 0:col with lines title columnheader

Now, suppose I would like to send GNUPlot an arbitrary columnar file with anywhere from 1:N columns, where N is arbitrary.

Since I am opening a pipe from within GNUPlot, it seems that I will not be able to read from it to determine the number of columns. How do I tell GNUPlot (in a clean way) to simply plot each column until there are none left to plot?

1

1 Answers

1
votes
  plot for [col=2:*] file using 0:col with lines title columnheader

However, if you know what the file name is in order to issue the "cat" command you would do better to just pass the filename to gnuplot rather than using a pipe.

  gnuplot -e 'file="foofile"' plot.p

Alternatively, you can feed the input via channels other than /dev/stdin. Here is an excerpt from the documentation section for piped-data:

 On systems with an fdopen() function, data can be read from an arbitrary file
 descriptor attached to either a file or pipe.  To read from file descriptor
 `n` use `'<&n'`.  This allows you to easily pipe in several data files in a
 single call from a POSIX shell:

       $ gnuplot -p -e "plot '<&3', '<&4'" 3<data-3 4<data-4
       $ ./gnuplot 5< <(myprogram -with -options)
       gnuplot> plot '<&5'