Hi,
I need to read two colums(4th and 5th) from a file and do some manipulation
Input file is
401500 IOC Q 14 14
406200 LC Q 1 1
410124 IOC Q 5 4
410124 LC Q 11 8
410132 IOC Q 230 229
410148 IOC Q 5 5
410148 LC Q 11 11
410156 IOC Q 116 116
410156 LC Q 2038 2031
condition that i need to check is
f $4 > $5
diff = $4-$5
elif $5 > $4
diff=$5-$4
errpct = $4*0.05
if errpct > diff
error
else if errpct -le diff
success
How can i achive this using shell script. Please help
What have you done to attempt to solve this problem?
Post your sample script, and we'll see how we can assist.
Regards
nawk '{
errpct=$4*0.05
if ($4>$5)
diff=$4-$5
else
diff=$5-$4
if (errpct > diff)
print $0" error"
else
print $0" success"
}' file
output:
401500 IOC Q 14 14 error
406200 LC Q 1 1 error
410124 IOC Q 5 4 success
410124 LC Q 11 8 success
410132 IOC Q 230 229 error
410148 IOC Q 5 5 error
410148 LC Q 11 11 error
410156 IOC Q 116 116 error
410156 LC Q 2038 2031 error
Using Conditional Operators
awk '{if (($4*0.05) > ( ($4>$5 ? $4-$5 : $5-$4))) print $0,"error"
else
print $0,"Success" }' test1
401500 IOC Q 14 14 error
406200 LC Q 1 1 error
410124 IOC Q 5 4 Success
410124 LC Q 11 8 Success
410132 IOC Q 230 229 error
410148 IOC Q 5 5 error
410148 LC Q 11 11 error
410156 IOC Q 116 116 error
410156 LC Q 2038 2031 error