awk lets you select the lines to extract through boolean expressions, that includes involving the column data themselves, or line numbers through NR.
set col$j = `awk -v cn=$j '$2 > 0.579 {print $cn}' fornax.dat`
set col$j = `awk -v cn=$j '$2>0.579 && $2<1.0 {print $cn}' fornax.dat`
set col4 = `awk 'sqrt($1*$1+$2*$2) > 1 {print $4};' fornax.dat`
set col2 = `awk 'NR<=5 || NR>10 {print $2}' fornax.dat`
set col2 = `awk '$0!~/-999/ {print $2}' fornax.dat`
set nrow = $#col2.
The first example only includes those values in column 2 that exceed
0.579. The second further restricts the values to be no greater than 1.0.
The third case involves the square-root of the sum of the squares of
the first two columns. The fourth omits the sixth to tenth rows.
The fifth example tests for the absence of a null value, -999.
You can find out how many values were extracted through $#var, such as in the final line above.
You have the standard relational and boolean operators
available, as well as
and !
for match and does not match
respectively. These last two con involve regular expressions
giving powerful selection tools.
C-shell Cookbook