Why does “1” in awk print the current line?

In awk,

Since 1 always evaluates to true, it performs default operation {print $0}, hence prints the current line stored in $0

So, awk '$2=="no"{$3="N/A"}1' file is equivalent to and shorthand of

awk '$2=="no"{$3="N/A"} {print $0}' file

Again $0 is default argument to print, so you could also write

awk '$2=="no"{$3="N/A"} {print}' file

In-fact you could also use any non-zero number or any condition which always evaluates to true in place of 1

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)