How to display only lines 12-24 of an arbitrary text file?
I have a bunch of text files and I would like to display lines 12-14 by running a bash script for each file.
For one of the files, this works:
tail -14 | head -11
But since the other files are of different lengths, I cannot run the same script with them.
What is the command I'm looking for to output lines 12-24 of a text file?
source to share
Usage awk
:
awk '12<= NR && NR <= 24' file
B awk
, NR
- line number. The above condition insists on being NR
greater than or equal to 12 and less than or equal to 24. If so, then the line is printed. Otherwise it is not.
More efficient solution
It would be more efficient to stop reading the file after the upper limit is reached. This solution does the following:
awk 'NR>24 {exit;} NR>=12' file
source to share