Question

Is there a method to use multiple pipes when reading data with Gnuplot? The following will plot data received directly from the SQL statement.

plot "< sqlite3 tomato-rstats.db \"SELECT data FROM table;\""

What I'd like is to process that data before it reaches Gnuplot. I know that I could pipe the SQL data through the script, output to an intermediary file, and plot that file, but I'd rather skip the temp file. I imagined something along the lines of the following, but it's clearly not the correct syntax.

plot "< sqlite3 tomato-rstats.db \"SELECT data FROM table;\" | process.pl"

or

plot "< process.pl < sqlite3 tomato-rstats.db \"SELECT data FROM table;\""

Is this possible through some other syntax?

Was it helpful?

Solution

Using

plot "< sqlite3 tomato-rstats.db \"SELECT data FROM table;\" | process.pl"

as you suggested works just fine in gnuplot. You can use any combination of piped commands as an input for gnuplot, e.g.,

plot "< cat file.txt | cut -f 5 | head -n 100" w l

plots the first 100 items in the fifth row of file.txt. It should be noted that using this as an input for plotting is useless as this processing can be done from within gnuplot itself, but it shows the possibilities of using your UNIX command line and its pipes for preprocessing input.

Needless to say, this does not work on non-UNIX systems, like Windows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top