Replace Null with 0 in 6th column in file

Hi Forum.

I tried to search for the solution online but I couldn't find specifically what I'm trying to achieve.

I want to replace Null with 0 in column position#6; Any other values would be retained.

Before:
52653363|3407732947|28-MAR-2014 11:47:28|A|4011||3200|D|SAV|152|06042|1MA4||CAD|31-JUL-2013|0|5265336|10|04-APR-2014|2001

52653363|3022280964|31-JUL-2013 10:53:01|D|3714|200.00|3000|D|SAV|152|06042|1MA30||CAD|19-MAR-2013|4|5265336|10|30-AUG-2013|6
After:
52653363|3407732947|28-MAR-2014 11:47:28|A|4011|0|3200|D|SAV|152|06042|1MA4||CAD|31-JUL-2013|0|5265336|10|04-APR-2014|2001

52653363|3022280964|31-JUL-2013 10:53:01|D|3714|200.00|3000|D|SAV|152|06042|1MA30||CAD|19-MAR-2013|4|5265336|10|30-AUG-2013|6

Thank you.

Try

awk '!$6{$6=0}1' FS="|" OFS="|" file
1 Like

Its safe to check NF ,if there is any blank line, slight modification to RudiC's solution

$ awk 'NF && !$6{$6=0}1' FS="|" OFS="|" file
1 Like

If you might have strings like "000" or "0.0" in field 6 that you don't want changed to "0", it might be safer to use:

awk 'NF && $6==""{$6=0}1' FS="|" OFS="|" file