Awk实用功能与脚本开发详解
1. 日期插入脚本
在编写格式化信函时,我们可能需要插入日期。以下脚本可以实现这一功能:
To: Peabody From: Sherman Date: @date I am writing you on @date to remind you about our special offer.使用awk脚本subdate.awk处理输入文件subdate.test,@date会被替换为当天日期:
$ awk -f subdate.awk subdate.test To: Peabody From: Sherman Date: Sun., May 05, 1996 I am writing you on Sun., May 05, 1996 to remind you about our special offer.2.close()函数
close()函数用于关闭打开的文件和管道,有以下几个重要用途:
-限制同时打开的管道数量:系统对同时打开的管道数量有限制,使用close()函数可以在使用完管道后关闭它,以便后续打开更多管道。例如: