![Reemplazar valores negativos en un archivo con ceros](https://rvso.com/image/1416699/Reemplazar%20valores%20negativos%20en%20un%20archivo%20con%20ceros.png)
Quiero reemplazar todos los valores negativos de un archivo con ceros. ¿Cómo puedo hacer esto en awk?
Lo intenté gsub
pero gsub(-*, 0)
no funciona... ¿Alguna idea?
Mi "código" es
awk '{gsub($(!/-/),"0",$2); print $1 "\t" $2} file.dat >file.dat
Respuesta1
Parece que estás intentando actualizar solo la segunda columna. Si ese es el caso, esto debería hacer:
awk '$2<0 {$2=0} 1' file > tmp_file && mv tmp_file file
Prueba
$ 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