Hi All,
Seeking for your assistance on how to condition it correctly.
cat file1.txt
290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00
290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00
290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
1st scenario:
if the fourth column contains 888s and 0s it is by DEPT and "DEPT" will appended into the end of file.
here's what i did and got successfully condition
for i in `ls *.txt`; do
ONE=${i}
flag="1"
while read line
do
DEPT=`echo $line | awk -F "," '{print $3}'`
SDEPT=`echo $line | awk -F "," '{print $4}'`
if [ "$SDEPT" == 888 ] || [ "$SDEPT" == 0 ]; then
flag="1"
else
flag="0"
break
fi
done <$i
if [ $flag == "1" ]
then
TWO="Area_by_DEPT"
else
TWO="Area_by_CLASS"
fi
uploadfile=`echo ${ONE} | awk -F'.' '{print $1}'`
sed -i -e "s/^/$DT_NOW_YYYYMMDD,${uploadfile},${TWO},/" ${ONE}
mv ${ONE} ${ONE}_${TWO}
done
My output is: file1.txt_Area_by_DEPT
i got the correct output.
cat file1.txt
290,1663,76,5,0,0.00,86.91,0.00,26.98,0.00
290,1663,52,2,0,0.00,0.00,0.00,0.00,0.00
290,1663,52,999,0,0.00,34.60,0.00,9.00,0.00
290,1663,16,705,0,0.00,34.60,0.00,9.00,0.00
2nd scenario:(including the 1st condition)
if the fourth column does not contains 888s and 0s it is by CLASS and "CLASS" will appended into the end of file.
here's what i've done.
for i in `ls *.txt`; do
ONE=${i}
flag="1"
while read line
do
DEPT=`echo $line | awk -F "," '{print $3}'`
SDEPT=`echo $line | awk -F "," '{print $4}'`
if [ "$SDEPT" != 888 ] || [ "$SDEPT" != 0 ]; then
flag="1"
else
flag="0"
break
fi
done <$i
if [ $flag == "1" ]
then
TWO="Area_by_DEPT"
else
TWO="Area_by_CLASS"
fi
uploadfile=`echo ${ONE} | awk -F'.' '{print $1}'`
sed -i -e "s/^/$DT_NOW_YYYYMMDD,${uploadfile},${TWO},/" ${ONE}
mv ${ONE} ${ONE}_${TWO}
done
My output: file1.txt_Area_by_CLASS
i got the successfull output because of the else statement
(else
flag="0"
break
fi
0
cat file1.txt
290,1663,76,888,0,0.00,86.91,0.00,26.98,0.00
290,1663,55,0,0,0.00,0.00,0.00,0.00,0.00
290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
290,1663,16,888,0,0.00,34.60,0.00,9.00,0.00
290,1663,1,888,0,0.00,34.60,0.00,9.00,0.00
3rd scenario: the condition 1, 2 will be included on this 3rd condition. here i'm stuck i don't know what to do.
if the 3rd column
contains 55, 16, 76 and the fourth column is equal to 888 and 0 it's by CLASS and "CLASS" will appended into the end of file.
Expected output will be file1.txt_Area_by_CLASS
Summary Condition:
if the 4th column = 888 or 0 then it's by DEPT
if the 4th column not equal 888 or 0 then it's by CLASS
if the 3rd column contains 55, 16, 76 and 4th column = 888 or 0 then it's the same as by CLASS
if the 3rd column contains 55, 16, 76 and 4th column not equal 888 or 0 then it's the same as by CLASS
Hope you understand.
Need your expertise guys.
Please advise,