- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- EOF within awk?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 04:36 AM
тАО08-22-2006 04:36 AM
awk -f script.awk `ls -t /tmp/logdir/log.*`
Is there a way within script.awk to know when you have reached the end of an individual file? (or know when all files have been processed?) script.awk matches patterns and processes an indeterminant number of records in each file. I want to totalize the value of these records.
TIA
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 04:41 AM
тАО08-22-2006 04:41 AM
Re: EOF within awk?
how about inbedding awk in a read loop
while not EOF
do
nice awk stuff
done < filename
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 04:45 AM
тАО08-22-2006 04:45 AM
SolutionThis example should total the sizes of the files using an ls -l:
my.awk
-------------------------
BEGIN {
tot = 0
}
{
tot += ($5 + 0)
}
END {
print "Total: ",tot
}
--------------------------------------
Invoke like this:
ls -l | awk -f my.awk
Note the ($5 + 0). That is intential as it forces the 5th field (the file length in ls -l) into a numeric context. The standard idiom to force a field to string context is to append a null string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 05:14 AM
тАО08-22-2006 05:14 AM
Re: EOF within awk?
the BEGIN & END were what I needed - the proper format and syntax was what I was lacking...your example answered my question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 05:16 AM
тАО08-22-2006 05:16 AM
Re: EOF within awk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 05:18 AM
тАО08-22-2006 05:18 AM
Re: EOF within awk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 05:23 AM
тАО08-22-2006 05:23 AM
Re: EOF within awk?
awk '{c[FILENAME]+=$2}END {for (f in c) {print f,c[f]}}' *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2006 05:37 AM
тАО08-22-2006 05:37 AM
Re: EOF within awk?
How about(?):
# cat .nbrlines
#!/usr/bin/perl
while (<>) {
if (eof) {
printf "%8d %s\n", $., $ARGV;
close ARGV if eof;
}
}
...now:
# ./nbrlines /etc/hosts /etc/services
21 /etc/hosts
187 /etc/services
Regards!
...JRF...
- Tags:
- Perl