实用 awk 程序集合
1. 字符转译相关
在一些较旧的系统(如 Solaris)中,系统版本的tr工具可能要求列表写成方括号括起来的范围表达式(如[a-z])并加上引号,以防止 shell 进行文件名扩展。
以下是一个简单的时间检查和处理程序:
if (naptime <= 0) { print "alarm: time is in the past!" > "/dev/stderr" exit 1 }该程序会检查naptime是否小于等于 0,如果是则输出错误信息并退出程序。
之后程序会使用system()函数调用sleep工具:
# zzzzzz..... go away if interrupted if (system(sprintf("sleep %d", naptime)) != 0) exit 1 # time to notify! command = sprintf("sleep %d", delay) for (i = 1; i <= count; i++) { print message # if sleep command interrupted, go away if (system(command) != 0) br