I am working with a huge CSV file (filename.csv) that contains two columns. From column 1, I wanted to read current row and compare it with the value of the previous row. If it is greater OR equal, continue comparing and if the value of the current cell is smaller than the previous row - then i wanted to jump to the second column and take the value in the current row (of the second column). Next I wanted to divided the value larger value we got in column 1 by the value in the same cell of column two. For example in the following table: the smaller value we will get depending on my requirement is 327 (because 327 is smaller than the previous value 340) - and then we take 500 (which is the corresponding cell value on column two). Finally we divide 340 by 500 and get the value 0.68. My bash script should exit right after we print the value to the console.
338 800
338 550
339 670
340 600
327 500
301 430
299 350
284 339
284 338
283 335
283 330
283 310
282 310
282 300
282 300
283 290
In the following script, it works only for column 1 but i want to extend it for two columns based on my criteria i mentioned above.
awk '$1<p{
val=$1/p
if(val>=0.8 && val<=0.9)
{
print "value is:" $1/p
print "A"
}
else if(val==0.8)
{
print "B"
}
else if(val>=0.6 && val <=0.7)
{
print "C"
}
else if(val==0.5)
{
print "E"
}
else
{
print "D"
}
exit
}
{
p=$1
}' filetest.csv
How can we loop through the values in two columns and perform control statement?
PS: the criteria for my if-else statement is (if the value is >=0.8 and <=0.9, print A, else if the value) is >=0.7 and <=0.8, print B, if the value is >=0.5 and <=0.7 print C otherwise print D).
0.654is bigger than0.65, that's why it doesn't fit any of your conditions