Awk by Example

Here are some examples of GNU Awk, re-implementing common command line tools in Awk code one-liners to illustrate how Awk works. First line is the original tool, second line is the Awk equivalent. Obviously you would not do these tasks in Awk, rather you would combine these techniques into more complex actions difficult or impossible in the shell.

[Read More]

Working with the newest or oldest files

I recently wanted to delete all but the most recent 3 daily backup files. Deleting based on timestamp isn’t safe in this case; if you delete files older than 3 days then you’ll lose all backup files if the backup stops creating new backups for some reason. It’s relatively easy to work with files older or newer than a particular date but it’s less obvious how to deal with the N oldest or newest files, regardless of absolute timestamp, without writing a script.

[Read More]

Multi Stage LDAP Searches With Awk

Problem: query LDAP for all users in a particular group, when LDAP is set up in POSIX style (memberUID: in each group record instead of memberOf: in each user record) without writing a script.

[Read More]
awk  noscript  ldap