Is this really an awk problem?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Is this really an awk problem?
# 1  
Old 01-06-2006
Is this really an awk problem?

Hi,

I've got a problem with awk.

On a solaris box:

SunOS 5.8 Generic_108528-23 sun4u sparc SUNW,Sun-Fire-280R,

I am running the follow awk script:

# awk -f jawk ntest.dat
awk: too many output files 10
record number 11
#

Where jawk is:

#!/usr/bin/ksh

{
printf "%-9s%8s %14s %12s %12s %12s %4s\n",$2,$3,$4,$5,$6,$7,$8 > "/tmp/db_"$1"_size.dat"
}

and ntest.dat is:

dbase01 20060105 0 222429184 8650752 3407872 589824 0
dbase02 20060105 16790 902758400 152109056 137756672 40566784 24
dbase03 20060105 4615 358940672 93650944 3473408 589824 0
dbase04 20060105 12386 2824798208 920715264 897843200 2031616 2
dbase05 20060105 20020 1939275776 381419520 637599744 56950784 0
dbase06 20060105 11546 987693056 109379584 108724224 49283072 4
dbase07 20060105 52690 6660947968 1686372352 2625372160 720896 1
dbase08 20060105 0 5020123136 25624576 3138387968 589824 3
dbase09 20060105 5916 1072562176 214040576 255655936 124583936 2
dbase10 20060105 13552 2158428160 237043712 1011941376 275578880 6
dbase11 20060105 109663 7101677568 1193672704 1851523072 40960000 0
dbase12 20060105 4425 361693184 50397184 61931520 589824 2
dbase13 20060105 215021 9385213952 1095434240 2484994048 1572864 2
dbase14 20060105 16993 1485438976 351731712 264241152 21954560 7
dbase15 20060105 11573 704905216 127008768 146800640 786432 4
dbase16 20060105 34272 1623719936 365821952 599457792 37748736 3
dbase17 20060105 60282 5028380672 617742336 2058551296 88866816 8
dbase18 20060105 36540 3106340864 1340669952 274595840 14155776 5
dbase19 20060105 0 291241984 8781824 3407872 589824 0
dbase20 20060105 128790 10186063872 1776091136 5656215552 121110528 0
dbase21 20060105 14211 1107689472 365821952 176881664 107151360 6
dbase22 20060105 26699 1458503680 113442816 361168896 2555904 8

Despite the error message when the script is run, output is produced
in /tmp for the first 10 rows in ntest.dat:

# ls -lt /tmp/*.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase01_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase02_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase03_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase04_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase05_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase06_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase07_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase08_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase09_size.dat
-rw-r--r-- 1 root other 77 Jan 6 12:12 /tmp/db_dbase10_size.dat

When I reduce the number of rows in the ntest.dat file to 9 and run:

# awk -f jawk ntest.dat

This runs succesfully, as it does for ntest.dat when there are 10 rows in ntest.dat.

However, when there are 11 rows in ntest.dat the script errors with the error:

awk: too many output files 10
record number 11

I have tried deleting the current 11th row in the file to eliminate the data in the current 11th row, but still get the same error.
I have also tried different combination of rows on to get 11+ rows in the
ntest.dat file; whenever there are more than 10 rows in the ntest.dat file
the awk script errors with same error, despite generating the correct output
for the first 10 rows in ntest.dat.

This implies that the error is not associated with the awk processing, but
that the awk script is reporting an error from the OS. There is ample
space in /tmp (the output files are 77 Kb).

On this server in /usr/include/limits.h the following parameters are defined:

#define CHILD_MAX 25 /* max # of processes per user id */

#define OPEN_MAX 256 /* max # of files a process can have open */

Running ps -efl | grep root | grep -v grep | wc -l before and after running the awk script returns 71.

Does anyone know why awk behaves in this way?

Thanks in anticipation,

Jon
# 2  
Old 01-06-2006
Code:
#!/usr/bin/nawk -f

{
output="/tmp/db_" $1 "_size.dat"
printf "%-9s%8s %14s %12s %12s %12s %4s\n",$2,$3,$4,$5,$6,$7,$8 > output
close(output)
}

# 3  
Old 01-06-2006
nawk solves the problem

Thank-you very much, nawk has solved the problem.
Can anyone explain what the limitations of awk in the initial problem
were?

Thanks in anticipation,

J
# 4  
Old 01-06-2006
The problem was with the number of the concurrently openned streams, i.e. openned file descriptors you're writting to:
Code:
..... > "/tmp/db_"$1"_size.dat"

Most awk's have a limit on how many files/streams you can keep openned at any given time. In the case of the Solaris' "awk" [a really old version of awk] I believe it's 10.

You kept creating output streams/files based on the value of the first column of the file. Therefore the number of streams could go OVER the maximum of 10.

The stream/file will remain openned till you close it explicitely with the 'close' call. Using the 'close' keeps the number of the concurrently openned streams/files to a minimum NOT going over the maximum numbe of 10.

Hope it helps.
# 5  
Old 01-10-2006
Message Understood

Thanks for taking the time to explain that to me.
A working version of the script has now been implemented.

J
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk problem

Hi I have two columns and I would like to create a third column based on how many lines away from a value of 1 in column 2, for example I have 1,0 2,0 3,0 4,0 5,0 6,1 7,0 8,0 9,0 10,0 11,1 And I want an output (6 Replies)
Discussion started by: garethsays
6 Replies

2. Shell Programming and Scripting

awk problem

i have an email list in file.txt with comma separated line1 - FIELD1,pippo@gmail.com,darth@gmail.com line2 - FIELD2,pippo@gmail.com,darth@gmail.com,sampei@gmail.com output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3,$4}' spreadsheet.txt)but awk delete some letters at the... (8 Replies)
Discussion started by: pasaico
8 Replies

3. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. UNIX for Dummies Questions & Answers

Little problem with AWK

I thought I had solved this problem but after testing the script I came to realize that it is not doing what I need. So, here it goes again. This is the code: awk '/\>/{F=$2; N=$3; split(FILENAME, A, "."); getline; x = ">"}{print ">" A"-" x++" "F" " N"\n" $0}' This is the input file: ... (5 Replies)
Discussion started by: Xterra
5 Replies

5. Shell Programming and Scripting

awk problem

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files. i tried with awk $>ls -lh | awk '/^-/ && $5 >= 100k {print $8 $5}' but it is not working pls tell... (3 Replies)
Discussion started by: abhikamune
3 Replies

6. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

7. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

8. Shell Programming and Scripting

problem using awk

Hi there every body I'm new to shell scripting and there is a problem facing me,, please look at the following piece of code: awk ' BEGIN{ FS="<assertion id=\1"; RS="<assertion id=\"2"}/<assertion id=\"1/{print FS$2 > "/home/ds2/test/output.txt"} ' filename all I wanna do is to... (6 Replies)
Discussion started by: senior_ahmed
6 Replies

9. Shell Programming and Scripting

Problem with AWK

Hi All, How can i store a value of the unix command executed in AWK with system command. devise=`cut -c1-3 dvgp.txt` I wrote this command in awk as awk'{ code= sprintf("devise=`cut -c1-3 dvgp.txt`"); system(code); }' Is this correct. can you please suggest me how the code can be... (1 Reply)
Discussion started by: krishna_gnv
1 Replies

10. UNIX for Dummies Questions & Answers

AWK Problem

Hi, I posted something here about this yesterday but I can't seem to find it. I needed help writting a script which would append a file with new lines after every so many charachters. Example: (my original flat file) L60 LETTER OF CREDIT 60 DAYS W00 ON RECEIPT WIRE TRANSFER W30 NET... (12 Replies)
Discussion started by: gseyforth
12 Replies
Login or Register to Ask a Question