[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Statements as functions?
From: |
Jim Mellander |
Subject: |
Statements as functions? |
Date: |
Sun, 23 Feb 2025 17:37:28 -0800 |
I found a case where I would kinda like to execute a statement as a
function, kinda like some other languages (lua, e.g.) do.
Here's a fragment from a script that processes thttpd logs and creates a
count of unique IPs per day hitting a webserver, excluding spiders:
# Print date & IP if different from previous line of input
# date " " ip
! ($1 in spider) && ((l = substr($4,2,11) " " $1) != lastline) {
print lastline = l
}
What would be nice (not essential by any means) would be to be able to code
it all in the pattern section, like this:
! ($1 in spider) && ((l = substr($4,2,11) " " $1) != lastline && print
lastline = l) { }
print could return the count of characters printed. Similarly, a for loop
could return the number of iterations. Obviously, a counter in the for loop
could serve the same purpose, and a helper function to print can be used in
my case (but not in the general case).
So, this isn't really a feature request, but kind of a nice to have...
My first post to the list, been using awk for decades...
- Statements as functions?,
Jim Mellander <=