2

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.

1 Answer 1

2

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").

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you for answering. I have tried the two solutions, but it tells 'data file no valid data points '. plot "<awk -F, 'NR>8{ print $46, $47 }' ratio_T.csv | sort -nk46" u 1:2 w linespoints ls 20 and also tried -nk1. Have you plotted the data?.
This is just because the data coming out of your awk script no longer has a comma (,) between the items. Remove the line set datafile separator "," and it should work.
Also, you should change the sort -nk46 as you only have 2 columns after the awk.
It does not work for me. I have removed the sort -nk and the set datafile separator ",".
Your numbers are all inside double-quotes, which is unusual. If you remove them by adding | sed 's/\"//g' between the awk and the sort, it should work better.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.