In Gnuplot 5.4, a special symbol $# was introduced, which represents the number of columns available within a using specifier. This addition enables scripts to dynamically adapt to varying numbers of columns in a data file.
When combined with the sum expression, $# allows users to iterate over all columns in each row, performing operations such as aggregating or concatenating their values. One particularly useful application is reformatting multi-column data into a single-column format, which can be helpful when plotting overlapping spectra or time series that were originally stored as separate columns.
The example below reads a file containing multi-column spectral data (spectrum_07.txt), concatenates all column values row-by-row into a single column, and stores the result in a data block. This reformatted data is then plotted as a continuous line:
set print $data
data = ""
stats "spectrum_07.txt" using (sum [k=1:int($#)] (data = data.strcol(k)."\n", 0), 0) nooutput
print data
set print
plot $data with lines