The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
If you know the number of lines, subtract three and print up through that number.

Radoulov's solutions are superior, as usual, although they will read the entire file into memory at once, whereas the following basically operates the file a line at a time.

Code:
lines=$(wc -l <inputfile)
wanted=`expr $lines - 3`
head -n $wanted inputfile >outputfile
Reply With Quote