For sorting a file by column, Linux users have the utility sort.
Windows users have to install, e.g. CoreUtils from GnuWin to get the same (or similar) functionality.
So, the minimal code for sorting the file first by column1 and then by column2, and then plotting the file would be something like this:
plot '<sort -k 1,2 "myFile.dat"' u 1:2
Now, however, I have a datablock $Data:
$Data <<EOD
1 6
4 8
3 7
2 5
1 4
2 3
EOD
The commands I tried so far which all end up in error messages:
plot '<sort -k 1,2' $Data u 1:2
#--> Bad data on line 1 of file <sort -k 1,2
plot '<sort -k 1,2 $Data' u 1:2
plot '<sort -k 1,2 <$Data' u 1:2
#--> warning: Skipping data file with no valid points
#--> x range is invalid
plot '<sort -k 1,2 '<$Data u 1:2
#--> Column number or datablock line expected
I don't want to write the datablock to a file first and read it again from file. I currently don't see how I would redirect the content of $Data to the standard input of sort. Is there any solution for Windows as well as for Linux?
Update:
When using @Ethan's suggested code, I get the following result. Mind the lines 2 5 and 2 3 which I expected (and Ethan has it) the other way round.
# Curve 0 of 1, 6 points
# Curve title: "$Data_1 using 1:2:1"
# x y type
1 4 i
1 6 i
2 5 i
2 3 i
3 7 i
4 8 i
Any idea why this is? I'm running gnuplot 5.4.1 on Win10.
