Pass shell variable to gnuplot


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass shell variable to gnuplot
# 1  
Old 05-02-2012
Pass shell variable to gnuplot

Hi
I am plotting a series of CDFs using gnuplot using
Code:
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
Code:
cat file | grep CONDITION | wc -l

and pass it on to gnuplot by any means?

Thanks a lot.
# 2  
Old 05-02-2012
Yes.

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

# 3  
Old 05-02-2012
Another way is things like this:

Code:
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.
# 4  
Old 05-03-2012
wow thanks guys! trying it out Smilie Smilie

---------- 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-
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 Smilie
# 5  
Old 05-03-2012
Try using backquotes instead of the $() syntax. Like this:
var=`command`



Lee Phillips
----------------
gnuplot Cookbook
Available on Amazon
# 6  
Old 05-04-2012
Hi

Placing ` ` seems to have cleared the error that I was getting. But now I am getting an error here
Code:
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. :-|

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

Last edited by jamie_123; 05-04-2012 at 04:52 AM.. Reason: update
# 7  
Old 05-04-2012
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable from awk script to shell?

Hi, Please need to print the Rej variable outsite the awk script which is given below...please advised how to achieve it. #!/bin/bash echo "Enter DMU Pipe delimited File name for the Feed to be validated" read DMU_File echo "Enter Pre-DMU File name for the Feed" read Predum_file ... (3 Replies)
Discussion started by: pelethangjam
3 Replies

2. UNIX for Dummies Questions & Answers

Pass shell Variable to awk

Hello, May i please know how do i pass the shell variable to awk expression in the below script. It is returning null #!/bin/bash UNINUM=720922 UNINUM_DESC=`awk -F'|' -v UNINUM=$2 '/UNINUM/ {print $4}' datafile` echo $UNINUM_DESC datafile 4|First|720194|asdasdad 4|First|720735|asdasdsa... (8 Replies)
Discussion started by: Ariean
8 Replies

3. Shell Programming and Scripting

Pass awk array variable to shell

Hi, all suppose I have following myfile (delimited by tab) aa bb cc dd ee ffand I have following awk command: awk 'BEGIN{FS="\t"}{AwkArrayVar_1=$1;AwkArrayVar_2=$2};END{for(i=0; i<NR; i++) print i, AwkArrayVar_1, AwkArrayVar_2,}' myfileMy question is: how can I assign the awk array... (7 Replies)
Discussion started by: littlewenwen
7 Replies

4. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. Shell Programming and Scripting

How to pass variable with spaces from shell to expect?

I need call expect script from shell script and pass values some of which could contain space. How to make expect to treat such values as one variable? (1 Reply)
Discussion started by: urello
1 Replies

6. UNIX for Dummies Questions & Answers

How to pass a variable from shell to awk

I know this topic has been dealt with previously, but the solutions I've seen don't work for me apparently. I need to pass a variable defined in the shell to one in awk: $ echo $var1 3 $ cat aaa aaa 1 bbb 2 ccc 3 ddd 4 eee 5I've tried this, without success: $ awk... (2 Replies)
Discussion started by: metaltree
2 Replies

7. Shell Programming and Scripting

Is it possible to pass variable from awk to shell back

I am passing a varaible to from Shell to awk then I am doing some maniplation for that variable inside awk. I want that maniplated variable value back to shell , Is this possible .Please let me know. (12 Replies)
Discussion started by: unishiva
12 Replies

8. Shell Programming and Scripting

Is it possible to pass variable from awk to shell script

Hello experts, can I return a value from gawk to a shell script ? My script as follows, #Here I want the num value to shell script so that I can use later gawk ' { split($0,num,","); print num }' gawk -v no=$number '{print no}' file1 ... (3 Replies)
Discussion started by: user_prady
3 Replies

9. UNIX for Dummies Questions & Answers

How to pass Shell script variable to awk

Hi, I have a shell script with an ambedded awk script. i need to pass a script variable to the awk script. Please help. Thanks in advance Himani (3 Replies)
Discussion started by: HIMANI
3 Replies

10. UNIX for Dummies Questions & Answers

How to Pass variable to shell Script

Hi , i am beginner to Unix, I have one small script which execute java programme,it has java command input output structure . Right now i have given Input output structure manually that is on same directory, now how can i pass that by commandline #!/bin/sh java Classjava input.txt... (5 Replies)
Discussion started by: sam70
5 Replies
Login or Register to Ask a Question