Hi All,
Seeking for your assistance on how to append the specific string when $3 condion met.
ex. file1.txt
ar0050046b16,5,888,0,0,0,0.00,0.00,0.00,0.00,25689.55
ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55
ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55
expected output: file1.txt_Area_by_1
file2.txt
ar0050046b16,5,888,0,0,0,0.00,0.00,0.00,0.00,25689.55
ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55
ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55
ar0050046b16,5,100,0,0,0,0.00,0.00,0.00,0.00,25689.55
expected output file2.txt_Area_by_2 since $3 has the records of 100
Condition: If $3 contains 888 or 0 it will append the filename into file1.txt_Area_by_1
else if $3 not contains to 888 or 0 then the filename will append file2.txt_Area_by_2
What i did was i use for loop:
#!/bin/sh
for i in `ls *.txt`
do
DEPT=`awk -F "," '{print $3}' $i`
echo "${DEPT}"
if [ "${DEPT}" == "888" ] || [ "${DEPT}" == "0" ]
then
flag=0
else
flag=1
fi
if [ $flag == "0" ]
then
echo "Area_by_DEPT"
else
echo "Area_by_CLASS"
fi
done
but the problem it's not working the way i want.
Please advise,
Thanks,