title: awk in non-interactive is leaving some data missing
body: <p>I'm running an awk command in a shell script, and it's breaking the datafile. All of the data doesn't load, and there's a newline character at the end of each line.</p>
  
  <pre><code>awk -v name="$filename" -v batch="$BATCHNAME" -F'|' 'BEGIN{OFS="|"}{$2=batch;print &gt; (name".locked.concur")}' $filename.locked.concur
  </code></pre>
  
  <p>If I run this as a command, it works perfectly.</p>
  
  <p>I've just found that i can use fflush() and it seems to have solved the issue.</p>
  
  <p>So now i have: </p>
  
  <pre><code>awk -v name="$filename" -v batch="$BATCHNAME" -F'|' 'BEGIN{OFS="|"}{$2=batch;print &gt; (name".locked.concur") fflush()}' $filename.locked.concur
  </code></pre>
  
  <p>Am I setting myself up for disaster?</p>
  
  <p>Also, the file is renamed to $filename.locked.concur0  --  I'm guessing this zero is the exit code that's returned from fflush? How do I get rid of this 0?</p>
  
  <p>full code:</p>
  
  <pre><code>for filename in `cat ${INFILEDIR}/file_list_concur`
  
  do
  
  rm -f $OHAP_DAT/bad/$filename.bad
  
  ##Create Batchname based on filename
  
  BATCH_GROUP=`ls $filename.locked.concur |cut -d '_' -f 1`
  BATCH_DATE=`ls $filename.locked.concur |cut -d '_' -f 2`
  BATCHNAME=${BATCH_GROUP}_Concur_${BATCH_DATE}
  
  echo 'Batch Date = '$BATCH_DATE
  echo 'Batch Group = '$BATCH_GROUP
  echo 'Batch Name = '$BATCHNAME
  echo 'File Name = ' $filename
  
  gawk -v name="$filename" -v batch="$BATCHNAME" -F'|' 'BEGIN{OFS="|"}{$2=batch;print &gt; (name".locked.concur");}' $filename.locked.concur
  
  
  ##End Batchname
  
  sqlldr $ORACLE_PW control=$XXOH_TOP/bin/XXOH_AP_CONCUR_IMPORT_CTL.ctl \
                data=$OHAP_DAT/in/$filename.locked.concur \
                log=$OHAP_DAT/log/$filename.log \
                bad=$OHAP_DAT/bad/$filename.bad \
                  bindsize=512000 &lt;&lt; end_of_sqlldr
  end_of_sqlldr
  
  if [ -f $OHAP_DAT/bad/$filename.bad ]
  then
    echo \!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    echo \!! 'date'
    echo \!! SQL*Loader bad file was found!!
    echo \!! Script $filename Failed - BAD FILE!
    echo \!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  </code></pre>