Reputation: 429
I m trying to get the first element of a file within gnuplot:
data = "file.dat"
x = `cat data | head -n 2 | tail -n 1 | awk '{print $1}'`
but this keeps giving me the following error:
no such file or directory
I should write something like
x = cat $data | head -n 2 | tail -n 1 | awk '{print $1}'
(with dollar)
Obviouly, this is also not correct.
Any ideas?
Upvotes: 5
Views: 5754
Reputation: 48440
Another possiblity instead of the backtics is to use the system
function. Then you can build any string and run it as shell expression:
data = 'file.dat'
x = system("head -n 2 ".data." | tail -n 1 | awk '{print $1}'")
Upvotes: 7
Reputation: 2819
You need to use a
set macro
and then use the symbol @
to get the value of the variable data
(@
in Gnuplot is like $
in bash)
so this should work
x = `cat @data | head -n 2 | tail -n 1 | awk '{print $1}'`
Upvotes: 7