The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Read a file and search a value in another file create third file using AWK King Kalyan Shell Programming and Scripting 11 06-19-2009 12:05 AM
Need help with awk - how to read a content of a file from every file from file list tanit Shell Programming and Scripting 7 03-10-2009 05:19 AM
file size comparision local file and remote file dba.admin2008 Shell Programming and Scripting 4 11-13-2008 05:57 PM
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
claw82 claw82 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 31
End of file in AWK

Hello!

I need to control when i arrive to the end of my file, any built-in? or another way to do?

Thanks!
  #2 (permalink)  
Old 1 Week Ago
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,291
No built-in for EOF in awk, you can do something like this:

Code:
awk -v eof=$(wc -l < file) '
NR==eof{print "Last line: " $0}
' file
  #3 (permalink)  
Old 1 Week Ago
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,502
the so called "EOF" in awk is the END{} block or when getline returns 0. what do you want to "control" ?
Code:
# more file
1
2
3
$ awk 'BEGIN{ while(1) { if ( (getline line < "file") == 0 ) {print "eof: "line;break} } }'
eof: 3

Last edited by ghostdog74; 1 Week Ago at 09:28 AM..
  #4 (permalink)  
Old 1 Week Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by claw82 View Post
Hello!

I need to control when i arrive to the end of my file, any built-in? or another way to do?
[...]
You have the END special pattern. If more than one input file is processed you can either use the new experimental ENDFILE pattern (available with a separate patch for Gnu AWK) or write it yourself using the FILENAME built-in variable.

This link is also relevant.
  #5 (permalink)  
Old 4 Days Ago
claw82 claw82 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 31
The solution proposed for Franklin is good for me, because i can't use the END instruction, i need to know the end of file in the body of my awk.

Thanks!
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0