awk date too many open files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk date too many open files
# 1  
Old 01-18-2018
awk date too many open files

Dear Community;

I have a csv file with msb and lsb in $3 and $5 fields which provides the epochtime (factor 65536). Further I need to convert epochtime to readable datetime.
But am getting an error.

File Sample:
Code:
5000a,1000,20671,0,16421,0,1,NULL,0
5000b,1000,20974,0,-16284,0,1,NULL,0
5000c,1000,20974,0,-16269,0,1,NULL,0
5000d,1000,20974,0,-16237,0,1,NULL,0
5000e,1000,20974,0,-16215,0,1,NULL,0
5000f,1000,20974,0,-16194,0,1,NULL,0
5000g,1000,20671,0,16421,0,1,NULL,0

Command:
Code:
awk -F, 'BEGIN {OFS = FS} {epochtime=($3*65536+$5)} {"date -r "epochtime"" | getline starttime} {$3=starttime; print}' offer_disabled.txt

Error:
Code:
awk: date -r 1374535870 makes too many open files
 input record number 33, file offer_disabled.txt
 source line number 1

Other Attempts (ref: similar issues)
Code:
awk -F, 'BEGIN {OFS = FS} {epochtime=($3*65536+$5)} {"date -r "epochtime"" | getline starttime; close(epochtime)} {$3=starttime; print}' offer_disabled.txt 

Or 

awk -F, 'BEGIN {OFS = FS} {epochtime=($3*65536+$5)} {"date -r "epochtime"" | getline starttime; close(starttime)} {$3=starttime; print}' offer_disabled.txt 

Or 
awk -F, 'BEGIN {OFS = FS} {epochtime=($3*65536+$5)} {"date -r "epochtime"" | getline starttime; close(epochtime); close(starttime)} {$3=starttime; print}' offer_disabled.txt 

Or 

awk -F, 'BEGIN {OFS = FS} {"date -r "$3*65536+$5"" | getline starttime; close(starttime)}  {$3=starttime; print}' offer_disabled.txt

But the same error is returned.

If I run line 33 output
Code:
date -r 1374535870

on CLI, it works fine.

Please guide on this issue.

########################

Just to add, am running this on OS X

########################


BR//
# 2  
Old 01-18-2018
What's your OS and date version? The -r has different meanings across systems.
Howsoever, try this modification of your code:
Code:
awk -F, 'BEGIN {OFS = FS} {cmd = "date -r" $3*65536+$5; cmd | getline starttime; close (cmd); $3=starttime; print}' file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-18-2018
Many Thanks Rudi; This worked fine.

Can you please suggest what I was doing wrong?

BR//
# 4  
Old 01-18-2018
You have to close the file or pipe with EXACTLY the name/string you opened it, identical char by char. Closing "epochtime" or "starttime" you missed the "date -r" partial string.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 01-18-2018
If you have GNU awk (gawk) on your system you could try using the strftime() internal which should run much more quickly:

Code:
gawk -F, 'BEGIN {OFS = FS} {$3=strftime("%a %b %e %Y %T",$3*65536+$5); print}' offer_disabled.txt


Adjust the format string %a %b %e %Y %T to your requirements:

Output:
Code:
5000a,1000,Wed Dec  5 2012 22:37:57,0,16421,0,1,NULL,0
5000b,1000,Tue Jul 23 2013 09:29:40,0,-16284,0,1,NULL,0
5000c,1000,Tue Jul 23 2013 09:29:55,0,-16269,0,1,NULL,0
5000d,1000,Tue Jul 23 2013 09:30:27,0,-16237,0,1,NULL,0
5000e,1000,Tue Jul 23 2013 09:30:49,0,-16215,0,1,NULL,0
5000f,1000,Tue Jul 23 2013 09:31:10,0,-16194,0,1,NULL,0
5000g,1000,Wed Dec  5 2012 22:37:57,0,16421,0,1,NULL,0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

awk (Too many open files)

Hi Team, This is my first post, hope I am doing it right. I have a large file, like 6 GB. Its a proxy file so vendor requested to change username from logs for saving the confidentiality of the user. This is the script I created (With the help of Google): awk '{ tmp="echo " $5 " |... (12 Replies)
Discussion started by: tealc
12 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

5. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

6. Shell Programming and Scripting

awk throws makes too many open files

Hi, I have a below awk script. BEGIN { FS=","; } { system("curl -v -H \"Authorization: SSWS test" -H \"Accept: application/json\" -H \"Content-Type: application/json\" -X POST \"https://tes.test.com/api/v1/users?activate=false\" -d \'{ \"profile\": { \"firstName\": \"" $1 "... (7 Replies)
Discussion started by: Krrishv
7 Replies

7. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

8. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

9. Shell Programming and Scripting

Finding files and sorting by date (find | awk)

I am wanting to search a directory tree and return files that are older than a specified datetime. So far straight forward with find, now I want to sort in date order and format the output. So far I have this, but is not working and there is a problem with "." in the file and/or path names. ... (2 Replies)
Discussion started by: larry2311
2 Replies

10. Shell Programming and Scripting

Sorting Files by date and moving files in date order

I need to build a k shell script that will sort files in a directory where files appear like this "XXXX_2008021213.DAT. I need to sort by date in the filename and then move files by individual date to a working folder. concatenate the files in the working folder then start a process once... (2 Replies)
Discussion started by: rebel64
2 Replies
Login or Register to Ask a Question