bash - How to make zero the entire row except the first column, if it has a zero in any other colum in Linux? -
i make 0 entire row except first column, if has 0 value in other column. e.g.,
ifile.txt 1 4.5 9 2 5.0 0 3 2.4 4 4 3.1 2 5 0.0 0 6 2.4 1 7 0.0 5 looking output ofile.txt 1 4.5 9 2 0.0 0 3 2.4 4 4 3.1 2 5 0.0 0 6 2.4 1 7 0.0 0
assuming columns in input file separated tabs:
awk -f'\t' '{ if ($2 == 0 || $3 == 0) { $2 = 0; $3 = 0 }; printf("%d\t%.1f\t%d\n", $1, $2, $3) }' ifile.txt
output:
1 4.5 9 2 0.0 0 3 2.4 4 4 3.1 2 5 0.0 0 6 2.4 1 7 0.0 0
Comments
Post a Comment