Article 5EEF6 Replace first 0 by 1 in specific column

Replace first 0 by 1 in specific column

by
karamunix
from LinuxQuestions.org on (#5EEF6)
Hi Everyone,

I'm trying to replace in same file only the first 0 found in the fourth column by 1.

And to keep remaining 0 under the fourth column as is without any change.

To mention that columns are separated by a comma.

0,0,0,1
0,0,0,4
0,0,0,0
0,0,0,0
0,0,1,0
0,0,0,5
0,0,0,3
0,0,0,0
0,0,2,2

Desired output should be:
-------------------------

0,0,0,1
0,0,0,4
0,0,0,1 --> Here the 0 in the third row for the fourth column was replaced by 1.
0,0,0,0 --> Here the 0 should not be changed.
0,0,1,0
0,0,0,5
0,0,0,3
0,0,0,0
0,0,2,2

If we run the script another time:
----------------------------------
Desired output should be:
-------------------------

0,0,0,1
0,0,0,4
0,0,0,1
0,0,0,1 --> Here the 0 was replaced by 1 this time and so on.
0,0,1,0
0,0,0,5
0,0,0,3
0,0,0,0
0,0,2,2

Any help would be very appreciated.

Thanks in advance.latest?d=yIl2AUoC8zA latest?i=QX3VHNYDJps:k4zVQ7d8bEU:F7zBnMy latest?i=QX3VHNYDJps:k4zVQ7d8bEU:V_sGLiP latest?d=qj6IDK7rITs latest?i=QX3VHNYDJps:k4zVQ7d8bEU:gIN9vFwQX3VHNYDJps
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments