Awk基本入门[4] Awk Conditional Statements and Loops
1、Simple If Statement 语法: if (conditional-expression) action 如果是多个action,则语法如下: if (conditional-expression) { action1; action2; } Print all the items with quantity <=5: $ awk -F "," '{ if ($5 <= 5) \ print "Only",$5,"qty of",$2, "is available"; }' \ items.txt Only 2 qty of Refrigerator is available Only 5 qty of Laser Printer is available 2、If Else Statement 语法: if (conditional-expression) action1 else action2 该语法与三元运算符类似: conditional-expression ? action1 : action2 ; The following example displays the message "Buy More" when the total quantity is <= 5, and prints "Sell More" when the total