You need to repeat the substitution until it changes:
sed ':a; s/||/|nil|/g; ta'
However, this will not handle empty fields at the beginning or end, for this you need two more templates:
sed 's/^|/nil|/; s/|$/|nil/; :a; s/||/|nil|/g; ta'
Testing
Input:
cat << EOF > infile
foo|||bar
qux||boo|fzx
|||
EOF
Run it:
<infile sed 's/^|/nil|/; s/|$/|nil/; :a; s/||/|nil|/g; ta'
Conclusion:
foo|nil|nil|bar
qux|nil|boo|fzx
nil|nil|nil|nil
awk path
awk '{ for(i=1;i<=NF;i++) if(length($i)==0) $i="nil" } 1' FS='|' OFS='|'
source
share