[X-Unix] Remove last ten lines of files

Victor Eijkhout eijkhout at cs.utk.edu
Mon Jan 5 12:32:49 PST 2004


At 21:45 +0900 2004/01/02, Kino wrote:
>On Jan 2, 2004, at 8:04 PM, Kuestner, Bjoern wrote:
>
>>does anybody have a simple solution to remove the last ten lines of files
>>(of variable length).
>
>#! /bin/sh
>
>i=`grep -c $ $*`
>j=`expr $i - 10`
>if [ $j -lt 1 ]; then
>j=$i
>fi
>head -n $j $*

  awk -v n=`tail -n +10 YOURFILE | wc -l` 'NR<n {print}' YOURFILE

Tada!

-- 
Victor Eijkhout <eijkhout at cs.utk.edu>, 329 Claxton, Comp Sci, UT, 
Knoxville TN 37996.
tel: 865 974 9308 (W), 865 673 6998 (H), 865 974 8296 (F)
http://www.cs.utk.edu/~eijkhout/



More information about the X-Unix mailing list