Reputation: 4135
Bash points an arrow to "else" and says "syntax error" in a provocative whining tone.
awk '{if($3 != 0) a = ($3/$4) print $0, a; else if($3==0) print $0, "-" }' file > out
Why?
Upvotes: 31
Views: 168259
Reputation: 651
You forgot braces around the if block, and a semicolon between the statements in the block.
awk '{if($3 != 0) {a = ($3/$4); print $0, a;} else if($3==0) print $0, "-" }' file > out
Upvotes: 41