In a number of situations, one may have to deal with files containing variable number of fields on each line. Often enough the fields one wants to plot can be described by their position from the end, rather than the beginning of the line.
It would be quite natural to plot "foo.txt" using 1:-2 -- except Gnuplot rejects the -2 as invalid instead of interpreting it as the next to last field of every record.
Note that negative column numbers already have special meaning.
-2means "the index number of the current data set within a file that contains multiple data sets".So your suggestion is reasonable but would have to use some other convention.
Oh, I see. Well, maybe, introducing awk's concept of
NFwould help? As in:plot "foo.txt" using 1:(NF - 2)?I don't know why it took me so long to figure out how to do this correctly. After several attempts that didn't work acceptably, there is now an implementation in the development version and queued for 5.4.2:
In the context of a
usingspecifier, the character sequence $# evaluates to the total number of fields available in the current line of data.