AWK Too many open streams to print/printf

hallow all i need your advice about this script

i have script like this:

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

/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"

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

How about this:

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}

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.

This should be a bit more optimised:

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}
1 Like

@cluber_xl:thx for advice i will test