![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| transforming a multiline record to single line | anju | Shell Programming and Scripting | 9 | 01-14-2008 07:55 AM |
| appending spaces to first line based on second record. | ammu | Shell Programming and Scripting | 2 | 11-16-2007 03:35 AM |
| Finding a character in first line of a record | bsandeep_80 | Shell Programming and Scripting | 14 | 07-26-2007 11:04 AM |
| Showing an extra record/line | srivsn | Filesystems, Disks and Memory | 1 | 05-06-2006 09:35 AM |
| how to extract last line in record | bjorb | Shell Programming and Scripting | 7 | 10-18-2005 02:12 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
AWK - if last line/record do something
Hello:
I am trying to perform a certain action if the current record is the last line of the input file. But I am unable to figure out how to determine the last line of a file in awk. I need to do something like this: awk '{ if (lastline == NR) Do Something}' myfile.txt I have tried the following in a Korn Shell script. lastRec=`wc -l myfile.txt | awk '{print $1}'` print $lastRec awk -v aLastRec="$lastRec" '{if (NR == $aLastRec) print NR ": This is the last record!"}' But I could not get it to recognize the $lastRec or $aLastRec. Can you please help? Thanks. |
|
||||
|
tail can do the job here
Code:
test `tail -1 data.file`=="pattern" && echo OK || echo NOK |
| Sponsored Links | ||
|
|