replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance,

input:
1
2.3
-0.4
-25
12
13
45
-12

desired output
1
2.3
0
0
12
13
45
0
awk '$0+0<0{$0=0}1' inputfile

or

sed 's/^-.*/0/' inputfile
1 Like

thanks much for these one-liners,:slight_smile:

awk -F- '{$0=$1+0}1' infile
1 Like
 
awk '$1<0{$0=0}1' input.txt
perl -lane 'if($_<0){print "0"}else{print $_}' input.txt
1 Like