AWK Too many open streams to print/printf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Too many open streams to print/printf
# 1  
Old 04-16-2012
AWK Too many open streams to print/printf

hallow all i need your advice about this script

i have script like this:
Code:
INDEX=/zpool1/NFS/INDEX/${1}
SCRIPT=/zpool1/NFS/script/${1}
LIST=SAMPLE

cd ${SCRIPT}
for i in `cat ${LIST}`
do
GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'`
/usr/xpg4/bin/awk -F ":" '{close(f);f=$4}{print >> "'${INDEX}/${GETDATE}/LIST_'"f".TCG"}' ${INDEX}/${i}
rm -f ${INDEX}/${i}
done
rm -f ${LIST}

if i run this code in linux in never get error but if i run this in solari
get output error like this
Code:
/usr/xpg4/bin/awk: line 0 (NR=302): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_262.TCG"
/usr/xpg4/bin/awk: line 0 (NR=301): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_304.TCG"
/usr/xpg4/bin/awk: line 0 (NR=291): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_110.TCG"
/usr/xpg4/bin/awk: line 0 (NR=284): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_054.TCG"
/usr/xpg4/bin/awk: line 0 (NR=294): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_921.TCG"
/usr/xpg4/bin/awk: line 0 (NR=285): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_607.TCG"
/usr/xpg4/bin/awk: line 0 (NR=302): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_667.TCG"
/usr/xpg4/bin/awk: line 0 (NR=302): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_636.TCG"
/usr/xpg4/bin/awk: line 0 (NR=299): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_144.TCG"
/usr/xpg4/bin/awk: line 0 (NR=332): too many open streams to print/printf onto "/zpool1/NFS/INDEX/iq04/20120406/LIST_815.TCG"

Smilie
so how i can run this script without error like above
i need your advice for my script to be running well

Last edited by zvtral; 07-31-2012 at 03:46 AM..
# 2  
Old 04-16-2012
How about this:

Code:
CDR_INDEX=/zpool1/NFS/INDEX/${1}
CDR_SCRIPT=/zpool1/NFS/script/${1}
LIST=SAMPLE
 
cd ${CDR_SCRIPT}
for i in `cat ${LIST}`
do
   GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'`
   /usr/xpg4/bin/awk -F ":" -vDIR="${CDR_INDEX}/${GETDATE}/" '{f=DIR "LIST_"$4".TCG"; print >> f; close(f)}' ${CDR_INDEX}/${i}
   rm -f ${CDR_INDEX}/${i}
done
rm -f ${LIST}

# 3  
Old 04-16-2012
You're not closing the right file, which is why you end up with too many files open. Chubler_XL's solution fixes that, making sure you close exactly what you're printing to.
# 4  
Old 04-16-2012
This should be a bit more optimised:
Code:
CDR_INDEX=/zpool1/NFS/INDEX/${1}
CDR_SCRIPT=/zpool1/NFS/script/${1}
LIST=SAMPLE
 
cd ${CDR_SCRIPT}
for i in `cat ${LIST}`
do
   /usr/xpg4/bin/awk -F ":" -vIDX="${CDR_INDEX}" -vI="$i" 'BEGIN{DIR=IDX"/"substr(I,9,8)}
       {f=DIR "/LIST_"$4".TCG"; print >> f; close(f)}' ${CDR_INDEX}/${i}
    rm -f ${CDR_INDEX}/${i}
done
rm -f ${LIST}

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 04-16-2012
@cluber_xl:thx for advice i will test
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

2. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies

3. Shell Programming and Scripting

How to combine print and printf on awk

# cat t.txt 2,3,4,5,A,2012-01-01 00:00:28 2,6,4,5,A,2012-01-02 00:00:28 2,7,4,5,A,2012-01-02 02:00:28 # awk -F"," '{OFS=",";print $2,"";printf("%s", strftime("%m%d%y",$6));printf("%s", strftime("%H%M%S \n",$6));print ("",$1)}' t.txt 3, 010170073332 ,2 6, 010170073332 ,2 7,... (3 Replies)
Discussion started by: before4
3 Replies

4. Shell Programming and Scripting

What's the difference between print and printf in command?

For example, in this command: ls /etc/rc0.d/ -print ls /etc/rc0.d/ -printfThe outputs are quite different, why? (7 Replies)
Discussion started by: Henryyy
7 Replies

5. Shell Programming and Scripting

awk with printf

Hi, I am using the following code to assign a count value to a variable. But I get nothing. Do you see anything wrong here. I am new to all this. $CTR=`remsh $m -l $MACHINES{$m} -n cat $output | grep -v sent | grep \"$input\" | sort -u | awk '{print $5}'`; Upto sort - u it's... (2 Replies)
Discussion started by: nurani
2 Replies

6. Shell Programming and Scripting

How to print a string using printf?

I want to print a string say "str1 str2 str3 str4" using printf. If I try printing it using printf it is printing as follows. output ------- str1 str2 str3 str4 btw I'm working in AIX. This is my first post in this forum :) regards, rakesh (4 Replies)
Discussion started by: enigmatrix
4 Replies

7. Shell Programming and Scripting

AWK printf help

Target file contains short text (never more than 1 line) and filenames. The format is, e.g.,: TEXT1 filename1 TEXT2 TEXT3 filename3dddd filename3dddd TEXT4 filename4 TEXT5 filename5dddd filename5dddd filename5 where dddd is a random 4-digit whole number. Desired output: (4 Replies)
Discussion started by: uiop44
4 Replies

8. Shell Programming and Scripting

IF and awk/printf

Hi Friends, Scripting newb here. So I'm trying to create a geektool script that uses awk and printf to output certain fields from top (namely command, cpu%, rsize, pid and time, in that order). After much trial and error, I've pretty much succeeded, with one exception. Any process whose name... (3 Replies)
Discussion started by: thom.mattson
3 Replies

9. Shell Programming and Scripting

awk and printf

echo $bbsize 1.5 echo $fillpercent .95 echo $bbsize | awk '{printf "%.2f\n",$0*$fillpercent}' 2.25 echo $bbsize | awk '{printf "%.2f\n",$0*.95}' 1.42 1.42 is what I'm expecting... echo $blocksize 4096 echo $bbsize | awk '{printf "%.2f\n",$0*$blocksize}' 2.25 echo $bbsize |... (3 Replies)
Discussion started by: xgringo
3 Replies

10. Shell Programming and Scripting

How to print a % within a printf() function using awk

Here is the code I'm using { printf("%11d %4.2f\% %4.2f\%\n", $1,$2,$3); } I want the output to look something like 1235415234 12.24% 52.46% Instead it looks something like 319203842 42.27\%4.2f\% How do I just print a "%" without awk or printf thinking I'm trying to do... (1 Reply)
Discussion started by: Awanka
1 Replies
Login or Register to Ask a Question