i need to add missing delimiters...

ladies, gents..

say i have a file that should have 10 fields... (9 delimiters)

some records have 10 fields, some have 5 some have 8, etc.. nothing consistent, but i need my file to have 9 delimiters on each line, even if its null fields..

how can i go line by line and add the correct # of delimiters if they are missing..

i have a dirty way... but looking for help on a more elegant solution...

thanks

my ugly way... works fine on small stuff.. but when you have 100's of files, ranging in size from 10 -200 fields.. its just not practical

this example... i expect 4 delimiters on each line...
(i dont need to substitute the delimiters, just used the 1's for ease of reading)

$ cat test.txt

a1b1c1

a1b

a1b1c1

cat test.txt | awk -F1 '{print $1 "|" $2 "|" $3 "|" $4}'

a|b|c|

a|b||

a|b|c|

thanks in advance..

ob

Something like this?

GNU Awk

radoulov@linux-jgly:~/Desktop> cat file
a1b1c1
a1b
a1b1c1
radoulov@linux-jgly:~/Desktop> awk -F1 NF=4 OFS=\| file 
a|b|c|
a|b||
a|b|c|

Cannot test it rigth now, but I think that with other Awks (like nawk for example) you may need to force the recalculation of the current record:

awk -F1 '{NF=4;$1=$1}1' OFS=\|

thanks much... the number of fields and output file separators seems to be what i was missing.. life is easier now.

works great.. thanks

ob