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.
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
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
Code:
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,
Last edited by znesotomayor; 05-05-2016 at 10:56 PM..
Reason: rephrase
I'm stuck on how to put all that condition. all my testing is wrong. my output is always file1.class although the 4th column is only 888 and 0. it's contradictory
Please take a step back and rephrase the logics/conditions. And, an input sample containing ALL cases plus an indication what should go where might be of invaluable help - for you as well.
Apologies Sir Rudic. How do i run it on if statement? i'm encountering command not found.
Code:
#!/bin/sh
for i in `ls *.txt`; do
while read line
do
DEPT=`echo $line | awk -F "," '{print $3}'`
SDEPT=`echo $line | awk -F "," '{print $4}'`
if ($SDEPT == 888 || $SDEPT == 0) && !($DEPT == 55 || $DEPT == 16 || $DEPT == 76); then
echo dept
else
class
fi
done <$i
done
Code:
output
test.sh: line 8: 888: command not found
test.sh: line 8: 888: command not found
test.sh: line 11: class: command not found
test.sh: line 8: 0: command not found
test.sh: line 8: 0: command not found
test.sh: line 11: class: command not found
test.sh: line 8: 888: command not found
test.sh: line 8: 888: command not found
test.sh: line 11: class: command not found
Hi All,
I am using below if condition to check whether null is passed as a parameter to the program
if or ;
then
echo "ABC">>$FILE
else
echo "CDF">>$FILE
fi
However it is saying me null=null command not found . Please help me with this (9 Replies)
Hi i am writing a script where i am running , 5 scripts together in 1 script .
Now what i want is when these 5 scripts run completely , i should execute some other commands like i have compile the data etc.
I have have 5 echo statements at the end of all those scripts .
Like echo "1 is done" in... (1 Reply)
Hi,
I need to use if condition for search a file pattern on a particular location.
cd $file_Path
if ||
then
do this
else
do that
fi
Can someone help me with the if part, how i can put those conditions?
make sure format should be *.file* and *.file
file is a keyword which i... (5 Replies)
Hi all,
I have task to delete two different files from all file system. one is core file & other is old file.
i can delete core file but for old file i have to mv in different location.
i wrote a script but it is not working.
i have a two variables in this script first one is delcnt &... (6 Replies)
a=rhino
b=crocodil
c=testsc
if && "$c" = testsc ]
then
echo "Test #5 succeeds."
else
echo "Test #5 fails."
fi
i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Hi ,
I am trying the following simple script . But it is always giving 1 output. Dont know why
#!/bin/sh
find . -name "a.log"
if ; then
echo "1"
else
echo "0"
fi
Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
hi,
actully i need the belp for the below.
host_list=" Host1 host2 host3 host4 "
n=`hostname`
i need to put the condition like the below
if n is among the host mention in the host_list if
then
#some stugg
else
# some other stuff
fi (1 Reply)
hi, :)
pls consider the following if statement
if //g') ]
then
........
else
.......
when i execute the script i am getting the following error
'(' unexpected
I am not able to find the mistake.
could anybody tell where i did mistake.
cheers
RRK (13 Replies)
Hi Guys,
I want to use if conition for my script. Before I used it tried it with some small test scripts. But it was not succeeded. My script and screen output as follows,
Script:
echo 'Do you think Yes or No (y/n) : '
read ans
echo You input anser as $ans
ans1=y
if ( $ans == $ans1... (5 Replies)