awk调用date命令

创建文件date.awk:

$8 == 107582685 {   cmd = "date +%Y-%m-%d-%H -d @\"" $11 "\""
                    while (cmd | getline line) {
                        print line
                    }
                    close(cmd)
                }

调用命令:

awk -f date.awk *.log | sort | uniq -dc | sort -nr

sort参数:

-n    // 以数值来排序
-r    // 降序

uniq参数:

-d    // 仅显示重复行
-c    // 在输出行前面加上每行在输入文件中出现的次数

 

参考资料:

Linux命令date日期时间和Unix时间戳互转

How can I pass variables from awk to a shell command?

Invoking 'date' command inside awk string, with +%a formatting

posted @ 2017-05-03 16:20  Sawyer Ford  阅读(3984)  评论(0编辑  收藏  举报