I\'m trying to get the values in column X at lines 5 to 5 + Y. I\'m guessing there\'s a quick way to do this with awk
. How is this done?
Use awk to print column 2 of lines 5 to 10:
awk 'NR==5,NR==10 {print $2}'
The optimization is that it exits after the last line of the desired range has been printed.
A range pattern was used:
A range pattern is made of two patterns separated by a comma, in the form ‘begpat, endpat’. It is used to match ranges of consecutive input records.
https://www.gnu.org/software/gawk/manual/html_node/Ranges.html
A pattern can be either a regexp pattern or an expression pattern. Above uses expression patterns to do comparisons with NR.
I assumed white space delimited columns, but provided an example of specifying a different delimiter with the -F
option.