user1993416
user1993416

Reputation: 768

Awk line work in terminal but not in Gnuplot plot

I have my data in a CSV file where the data starts at the 8th row. There are many columns but I want to show $46 and $47.

I have tried:

set encoding iso_8859_1
set key right bottom font "Helvetica,16" 
set ylabel "Average inventory ratio, {/Symbol g} [inventoried/total]" font "Helvetica,19"
set xlabel "Average time in system, {/Helvetica=19 @^{/=18-}T} [s] " font "Helvetica,19"

set xtics font "Helvetica,16"
set ytics font "Helvetica,16"
set terminal postscript eps enhanced color
set grid
set key spacing 1
set key title "Min. Stock 80%"
set key box
set output "_known_T.eps"
set datafile separator ","
plot "ratio_T.csv" every::8::18 using 46:47 w linespoints ls 20

enter image description here

which works fine but I would need to sort the data by the column $46 to plot the result.

I have tried the next AWK line:

awk -F, 'NR>8{ print $46, $47 }' ratio_T.csv | sort -nk46 | tr '",' ' '

that works fine if executed in the Terminalbut not with Gnuplot, making this:

plot '<awk -F, 'NR>8{ print $46, $47 }' ratio_T.csv | sort -nk46' u 1:2  w points ls 20

A link with the CSV file is in this link.

Upvotes: 2

Views: 70

Answers (1)

meuh
meuh

Reputation: 12255

You cannot nest quotes (like you can nest parentheses eg ((()()))). Instead you can mix single quotes within double-quotes, eg:

plot "<awk -F, 'NR>8{print $46, $47}' ratio_T.csv|sed 's/\"//g'|sort -nk1" ...

or if you prefer you can use 2 single quotes within single quotes and they become a single quote, which is less obvious, eg:

plot '<awk -F, ''NR>8{print $46, $47}'' ratio_T.csv|sed ''s/"//g''|sort -nk1' ...

Note that inside "..." be careful if using backslash \ as it is used to escape octal character codes, newlines and " (eg "\033 \" \n").

Upvotes: 2

Related Questions