LoginSignup
9
3

More than 5 years have passed since last update.

[ awk ] if文サンプル

Posted at

memo

sample.txt
cat sample.txt
#################
Alice 25 27 50
Bob 35 37 75
Caren 75 78 80
David 99 88 76

awk '{ avg=($2+$3+$4)/3; if (avg>=80 && avg<90) result="A"; else if (avg>=60 && avg<80) result="B"; else if (avg>=50 && avg<60) result="C"; else if (avg<50) result="FAIL"; else result="Other"; print $0,":",result; }' sample.txt

awk '{
avg = ($2+$3+$4)/3;
if ( avg >= 80 && avg < 90 ) result="A";
else if ( avg >= 60 && avg < 80) result ="B";
else if (avg < 50) result ="FAIL";
else result ="Other"
print $0,":",result;
}' 
9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3