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 the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-05-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
You can use the END statement to access the last record of the file:


Code:
awk  'END{ print "this is the last line :  ", $0, "  | and NR  is -> " NR, "do something else here..." }' myfile.txt

And don't use $ sign inside awk:


Code:

lastRec=`awk 'END{print NR}' myfile.txt`

awk -v aLastRec="$lastRec" '{if (NR == aLastRec) ... }' myfile.txt