![Substitua valores negativos em um arquivo por zeros](https://rvso.com/image/1416699/Substitua%20valores%20negativos%20em%20um%20arquivo%20por%20zeros.png)
Quero substituir todos os valores negativos em um arquivo por zeros. Como posso fazer isso no awk?
Tentei gsub
mas gsub(-*, 0)
não funcionou... Alguma ideia?
Meu "código" é
awk '{gsub($(!/-/),"0",$2); print $1 "\t" $2} file.dat >file.dat
Responder1
Parece que você está tentando atualizar apenas a segunda coluna. Se for esse o caso, isso deve fazer:
awk '$2<0 {$2=0} 1' file > tmp_file && mv tmp_file file
Teste
$ cat a
hello 2
hello 3
hello -1
hello -4
hello 0
$ awk '$2<0 {$2=0} 1' a
hello 2
hello 3
hello 0
hello 0
hello 0