Display/Read line 'N' in a text file using script
I was just wondering if there exists already an inbuilt Linux command to just display a particular line or range of lines in a text file. I normally use a "for" loop for this kind of thing and works well.
|
There may be a more elegant way, but if, for example, I wanted to display lines 23-30 I would use
head -30 <file> | tail -8 Or more generally, in a script FIRST_LINE=$1 LAST_LINE=$2 typeset -i NUM_LINES=$LAST_LINE-$FIRST_LINE+1 head -$LAST_LINE|tail -$NUM_LINES (I only just tried this code in ksh so apologies if it needs to be tweaked for bash). Iain. |
very elegant technique indeed...
|
All times are GMT -5. The time now is 10:40 PM. |