How to replace blank tab with zero in a file?

hi,

i need to replace a blank tab output in a file to zero.

input file:

2015/08/04 00:00:00                       171                       730579                         27088                 <blank>                             3823                          30273                  1621778             3284136                        284200                      1267655                418709                        1320811                         51865           <blank>                                                    198387                            518

output:

2015/08/04 00:00:00                       171                       730579                         27088                 0                             3823                          30273                  1621778             3284136                        284200                      1267655                418709                        1320811                         51865           0                                                    198387                            518

I guess you don't want sed 's/<blank>/0/g' file ; then you should supply more details, e.g. is that a <TAB> delimited file? Are all fields except the first one(or two?) numeric? Any spaces in there?

Yes all the fields are numeric except first one which is date.

the file is tab delimited and actually a output from sql query.

some of the rows are null so u see more space between column where it is null and i need to replace those blank null tab will zero.

Then try

awk -F"\t" '{for (i=2;i<=NF;i++) if (!$i) $i=0}1' OFS="\t" file

Sorry its not working.

awk -F"\t" '{for (i=2;i<=NF;i++) if (!$i) $i=0}1' OFS="\t" test

output

2015/08/04 00:00:00                       171                       730579                         27088                                              3823                          30273                  1621778             3284136                        284200                      1267655                418709                        1320811                         51865                                                                                198387                            518      
 awk -F"\t" '1; {for (i=2;i<=NF;i++) if (!$i) $i=0}1' OFS="\t" file
2015/08/04 00:00:00    171    730579    27088         3823    30273    1621778    3284136    284200    1267655    418709    1320811    51865         198387    518
2015/08/04 00:00:00    171    730579    27088    0    3823    30273    1621778    3284136    284200    1267655    418709    1320811    51865    0    198387    518

---------- Post updated at 19:44 ---------- Previous update was at 19:42 ----------

Is it possible that "\t" doesn't work for FS and OFS on your system? Try inserting it literally.

Are you in Solaris? If so use /usr/xpg4/bin/awk rather than awk.
Is you file in fact TAB delimited? The sample you posted is not.

--

Every awk should be able to understand "\t".

[..] if (!$i) [..]

Why not just

if($i=="")

than you can be sure Awk will treat it as an empty string.