In many cases you probably want to filter a raw data file in various fashions before plotting the data with gnuplot. In some cases, you may want to use only specific rows (e.g., from line 10 to 100) of a data file in your plot. With gnuplot, you can specify a range of data to plot in two different ways.
The first method is to use gnuplot's "every" option in the plot command. The "every" option is used in the following form:
plot "my.dat" every A:B:C:D:E:F A: line increment B: data block increment C: The first line D: The first data block E: The last line F: The last data block
To plot the data starting from line 10:
plot "my.dat" every ::10
To plot the data from line 10 to line 100:
plot "my.dat" every ::10::100
To plot data starting from the first line till line 100:
plot "my.dat" every ::::100
An alternative way to plot specific rows of data file is to use input redirection. That is, use any external program to process raw data file, and redirect the output to gnuplot. Assuming that sed is installed on your Linux system, you can simply do:
plot "<(sed -n '10,100p' my.dat)"
As you can imagine, sed program prints out data between line 10 and line 100, and feeds it to gnuplot for plotting.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.