Updated files information

I am using the below script to remove the rows which contains null values in the 3rd column.My requirement here is want to get the filenames which row is removed .please help me.

#!/usr/bin/sh
Scripts=/ushhquest/data001/Scripts

cd /ushhquest/data011/TgtFiles/MonthlyData
ls CUSTADDR*.txt > sample_txt_files
while read line
do
srcfile="/ushhquest/data012/TgtFiles/BMMonthlyData"$line
tgtfile=/ushhquest/data012/TgtFiles/BMMonthlyData/output.txt
awk -F, '$3 =="" {next}1' $srcfile >> $tgtfile
rm -f $srcfile
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"

try this...

#!/usr/bin/sh
Scripts=/ushhquest/data001/Scripts

cd /ushhquest/data011/TgtFiles/MonthlyData
ls CUSTADDR*.txt > sample_txt_files
while read line
do
srcfile="/ushhquest/data012/TgtFiles/BMMonthlyData"$line
tgtfile=/ushhquest/data012/TgtFiles/BMMonthlyData/output.txt
awk -F, '$3 =="" {next;}1' $srcfile >> $tgtfile
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi
#rm -f $srcfile # You don't need rm here...
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"

I have tried using single awk.. but getting below error..

awk -F, -v file="file_name" '$3 =="" {if(!x[file]){print file > test_temp};next}1' file1
foo1,good,dsd,sfdf
awk: (FILENAME=file1 FNR=2) fatal: expression for `>' redirection has null string value

its working thanks boss...

 
awk -F, '$3==""{a[FILENAME]++}END{for(i in a)print i}' CUSTADDR*.txt

awk has the in-built variable called FILENAME

The above command will show the files which has

below code is not showing the updated files correctly..not sure what the issue is.plz help me

#!/usr/bin/sh
Scripts=/ushhquest/data001/Scripts
 
cd /ushhquest/data011/TgtFiles/MonthlyData
ls CUSTADDR*.txt > sample_txt_files
while read line
do
srcfile="/ushhquest/data012/TgtFiles/BMMonthlyData"$line
tgtfile=/ushhquest/data012/TgtFiles/BMMonthlyData/output.txt
awk -F, '$3 =="" {next;}1' $srcfile >> $tgtfile
if [[ $(awk -F, '$3 =="" {print;exit}' $srcfile) ]]
then
echo $srcfile >> output_file # Here you get all the files which has $3 blank
fi
#rm -f $srcfile # You don't need rm here...
mv $tgtfile $srcfile
done<sample_txt_files
rm -f sample_txt_files
echo "completed"