carminat (49) [Avatar] Offline
#1
In "Gnuplot in Action", at the bottom of pg. 257 it is written:
"gnuplot currently doesn't have the ability to report the number of records in a data file."

This is just half the truth: gnuplot itself is not able to count, but it can get it done by the unix system.
To count the lines in my sample file "feig.txt" I did it as follows:

system("cat feig.txt | wc -l")

If you prefer, you can create the file "lines.gp" containing the single command
lines=system(" cat $0 | wc -l")
so that if from gnuplot you write
call "lines.gp" "feig.txt"
gnuplot will assign to the variable 'lines' the number of lines of the file "feig.txt"

Caveat: this method counts blank lines (or commented lines) as well: if you really need to deal with these latter case you should use a more refined system call.

Message was edited by:
carminat