Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk - too many open files issue / date parsing [duplicate]

Tags:

unix

awk

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

I'm using the following code to convert it into a unix timestamp:

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

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?

like image 785
Šimon Tóth Avatar asked Jun 23 '15 15:06

Šimon Tóth


1 Answers

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.

like image 87
Tom Fenech Avatar answered Oct 14 '22 09:10

Tom Fenech