awk-打开文件过多/日期解析 [英] awk - too many open files issue / date parsing
问题描述
我正在尝试分析以格式化日期列开头的日志文件:
06/22/2015 00:17:59
I'm trying to parse a log file that starts with a formatted date column:
06/22/2015 00:17:59
我正在使用以下代码将其转换为unix时间戳:
I'm using the following code to convert it into a unix timestamp:
unix="date -d\""$1" "$2"\" \"+%s\""; unix | getline timestamp;
但是,当我这样做时,awk失败并显示以下错误:
However, when I do this, awk fails with following error:
awk: (FILENAME=/dev/fd/63 FNR=263350) fatal: cannot open pipe 'date -d"06/22/2015 00:17:59" "+%s"' (Too many open files)
有什么方法可以处理此问题,或者以其他方式解析日期?
Any way to deal with this, or to parse the date differently?
推荐答案
您的问题是您需要关闭命令:
Your problem is that you need to close your command:
unix="date -d\""$1" "$2"\" \"+%s\""; unix | getline timestamp; close(unix)
如果不这样做,则会为输入文件中的每个记录打开一个新管道,这会导致您遇到问题.
If you don't do this, a new pipe is opened for each record in your input file, which leads to the problem that you are experiencing.
这篇关于awk-打开文件过多/日期解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!