Counting the number of characters

Hi all,

Can someone help me in getting the following o/p

I/p:
1157,306413,R,2009,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,5,405,0,0,102,102,102,102,102,102,102,103,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,,102,102,102,102,102,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

O/p:
1157,306413,R,2009,113,

The First four fields remains the same , after that come the number of Zero or Null characters before the first non-zero or non-null charqacter , in the example given above it is "5" and the count is 113.

Would be really helpful if some one can help me by giving a statement (preferably awk )for this.

Many Thanks in advance
Sri

Try:

awk -F, '{for(i=5;!$i>0 && i<=NF;i++);NF=5;$5=i-5}1' OFS=, infile

Thank you Scrutinizer,

Can you please explain me the logic , because this is just one step of my requirement i need to do some more steps in this , I would need the o/p of that 5th Coloumn , My final o/p should look something like this

I/p:
1157,306413,R,2009,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,5,405,0,0,102,102,102,102,102,102,102,103,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,,102,102,102,102,102,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

O/p:
1157,306413,R,2009,113,5,405,0,0,102,102,102,102,102,102,102,103,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,,102,102,102,102,102,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0

I need to remove the zeros or null before the non zero character and append it at the end so that my coloumn count remains the same

Many thanks in advance

Sorry,

That is not giving the count of zeros and nulls that was coming before the non null value,

Can you please give me a statement to delete these fields , probably we can append it as the last step of the script

Just combine the two

awk -F, '{s=x;for(i=5;!($i>0) && i<=NF;i++)s=s OFS $i;sub(s,OFS i-5);$0=$0s}1' OFS=, infile

What had you tried yourself?

It is not working ,

I was trying to get the o/p of the first command you have given save it as a file , Then remove the coloumns between the 6th coloumn and the coloumn we get from the 5th coloumn , then append this to the last of the file.

What isn't working?