jueves, junio 06, 2013

extract specific lines from text file

For the example we use to variables L1 for the first line number, L2 for the last line number.

L1=21
L2=33
FILE=x.txt

awk method:

awk -e "NR>=$L1&&NR<=$L2{print \$0}" $FILE

sed method:

sed -n "$L1,$L2 p" $FILE

head + tail method:

head -n $L2 $FILE | tail -n $(($L2-$L1+1))

No hay comentarios.: