How would I go about reading all lines between two specific lines?
Lets say line 23 is where I want to start, and line 56 is the last line to read, but it is not the end of the file.
How would I go about reading lines 23 thru 56? I will be outputting them to another file.
By row number like that is quite easy with awk
:
awk 'NR >= 23 && NR <= 56'
And either way, sed
makes it fun.
sed '23,56!d'
Or for a pattern,
sed '/start/,/end/!d'
I would go for sed, but a head/tail combination is possible as well:
head -n 56 file | tail -n $((56-23))
Well - I'm pretty sure there is an off-by-one-error inside. I'm going to find it. :)
Haha - know your errors, I found it:
head -n 56 file | tail -n $((56-23+1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With