Question

Imagine I have a bunch of file like that :

model: 12356

# BEGINNING OF DATA
1.0000000 1.301230484
1.1749304 2.809483900
...

I would like to plot several files like this one and set the title of my plot to the number of the model (here "12356").

The following command works for one file

plot "< tail -n +4 myfile.data" u 1:2 title sprintf("%d",\
    `head -n 1 myfile.data | cut -d ":" -f 2`)

but imagine now that I'm doing several plots using a for loop, the command would be :

plot for [file in list] "< tail -n +4".file u 1:2 title sprintf("%d",\
    `head -n 1 @file | cut -d ":" -f 2`)

When I do that, gnuplot tells me that file is not a string variable and can therefore not be used with the "@". Do you have any workaround ?

Was it helpful?

Solution

There is no need to use macros (@file). Just use the system function, which you give a concatenated string:

plot for [file in list] "< tail -n +4 ".file u 1:2 \
     title system("head -n 1 ".file." | cut -d ':' -f 2")

Don't know the exact reason why your command with the macro doesn't work.

OTHER TIPS

If you are on linux, you can use a list with the output of ls

List = "`echo $(ls *.dat | sort -V)`"
plot for [i in List] i u 1:2 title i

For a more complex ls command, the route of the file will appear, and that could be messy. You could remove it with

plot for [i in List] i u 1:2 title system('basename '.i)

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top