Pass shell variable to gnuplot

Hi
I am plotting a series of CDFs using gnuplot using

plot "data" u 1:(1./x.) smooth cumulative

I am doing this over many files and I need to tune the x value to the number of lines that meets a particular condition.

Is it possible to get the line count from shell using

cat file | grep CONDITION | wc -l

and pass it on to gnuplot by any means?

Thanks a lot.

Yes.

condition_cnt=$(grep -c 'CONDITION'  $file)
plot "data" u 1:(1./${condition_cnt}.) smooth cumulative

Another way is things like this:

gnuplot <<EOF
variable=$(shellcode)
etc
etc
plot "data" u 1:(1./x.) smooth cumulative
EOF

Just remember you'll have to escape dollar signs that actually belong in there.

wow thanks guys! trying it out :slight_smile: :slight_smile:

---------- Post updated at 01:33 PM ---------- Previous update was at 11:44 AM ----------

@Jim:

I tried out your suggestion and it returns me an error- Column number expected.

Here is my code-

cnt1=$(grep -c ''  $../processing_old/buffer_a.txt)
cnt2=$(grep -c 'ALTEREDPLAY'  $buffer_a.txt)
cnt3=$(grep -c ''  $../processing_new/buffer_a.txt)
cnt4=$(grep -c 'ALTEREDPLAY'  $../processing_new_3buff/buffer_a.txt)

plot  '../processing_old/buffer_a.txt' u 15:(1./cnt1.) title "Strobe 1.6" smooth cumulative ls 10 lw 6,\
        'buffer_a.txt' u 16:(16./cnt2.) title "Panic 1.6" smooth cumulative ls 3 lw 6,\
        '../processing_new/buffer_a.txt' u 15:(1./cnt3.) title "Strobe 2.0" smooth cumulative ls 8 lw 6,\
        '../processing_new_3buff/buffer_a.txt' u 16:(1./cnt4.) title "Panic 2.0" smooth cumulative ls 2 lw 6

What is wrong here :frowning:

Try using backquotes instead of the $() syntax. Like this:
var=`command`

Lee Phillips
----------------
gnuplot Cookbook
Available on Amazon

Hi

Placing ` ` seems to have cleared the error that I was getting. But now I am getting an error here

plot  '../processing_old/buffer_a.txt' u 15:(1./cnt1.) title "Strobe 1.6" smooth cumulative ls 10 lw 6,\
        'buffer_a.txt' u 16:(16./cnt2.) title "Panic 1.6" smooth cumulative ls 3 lw 6,\
        '../processing_new/buffer_a.txt' u 15:(1./cnt3.) title "Strobe 2.0" smooth cumulative ls 8 lw 6,\
        '../processing_new_3buff/buffer_a.txt' u 16:(1./cnt4.) title "Panic 2.0" smooth cumulative ls 2 lw 6

The error being invalid expression. :expressionless:

Also I get a similar error for the case of Corona688's suggestion as well.

Why do you have a dot after the variable name? You are writing "1./cnt1.", etc. Try it without the dot.

Lee Phillips
----------------
gnuplot Cookbook
Available on Amazon

Many thanks LeePhilips, Works like a charm now :slight_smile: