Awk - Too Many Open File Issues / Parsing

I am trying to parse a log file that starts with a formatted date column: 06/22/2015 00:17:59

I use the following code to convert it to a unix timestamp:

unix="date -d\""$1" "$2"\" \"+%s\""; unix | getline timestamp;

However, when I do this, awk fails with the 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 handle this or parse the date differently?

+5
source share
1 answer

Your problem is that you need to close your command:

 unix="date -d\""$1" "$2"\" \"+%s\""; unix | getline timestamp; close(unix) 

If you do not, a new channel opens for each entry in your input file, which leads to the problem you are facing.

+13
source

All Articles