i have a huge file and as an output some columns doesn\'t have a value, i need to fill these columns with 0 for further analysis. I can separate the columns with space or ta
If and only if your data only contains numbers and you have clear defined field separator FS
, you can use the following trick:
awk 'BEGIN{FS=OFS="\t"}{for(i=1;i<=NF;++i) $i+=0}1' file
By adding zero, we convert strings to numbers. Empty strings will be converted to the number zero. You can define your field separator to anything you like.
This, however, might be a bit slow since it will reparse $0
and split it into fields, every time you reassign a field $i
.
A faster way is the solution of Dennis Williamson