I have a text file with 4 columns. I need to modify the file so that the first sequence of 1's in the 4th column remain 1, but all other values in the 4th column be changed to 0.
I have tried the following awk command with multiple if statements but the variable fat doesn't seem to be updating properly.
`cat sample_data.txt`
72 29 16 0 <br>
73 30 16 0 <br>
74 31 16 0 <br>
75 32 16 1 <br>
76 33 16 1 <br>
77 34 16 1 <br>
78 35 16 0 <br>
79 36 16 0 <br>
80 37 16 0 <br>
81 38 16 0 <br>
82 39 16 0 <br>
83 40 16 0 <br>
84 41 16 0 <br>
85 42 16 0.55 <br>
86 43 16 0.57 <br>
87 44 16 0.41 <br>
88 45 16 0.58 <br>
89 46 16 1 <br>
90 47 16 1 <br>
91 48 16 1 <br>
92 49 16 1 <br>
93 50 16 0.59 <br>
94 51 16 0.52 <br>
95 52 16 0.43 <br>
`awk -v fat=1 '{if($4<1 && fat=1) {print $1,$2,$3,0;} else if($4=1 && fat=1) {fat=2;print $1,$2,$3,1;} else if($4=1 && fat=2) {fat=2;print $1,$2,$3,1;} else if($4<1 && fat=2) {fat=3;print $1,$2,$3,0} else if($4<1 && fat=3) {fat=3;print $1,$2,$3,0;} else if($4=1 && fat=3) {fat=3;print $1,$2,$3,0;}}' sample_data.txt`
I want this output:
72 29 16 0 <br>
73 30 16 0 <br>
74 31 16 0 <br>
75 32 16 1 <br>
76 33 16 1 <br>
77 34 16 1 <br>
78 35 16 0 <br>
79 36 16 0 <br>
80 37 16 0 <br>
81 38 16 0 <br>
82 39 16 0 <br>
83 40 16 0 <br>
84 41 16 0 <br>
85 42 16 0 <br>
86 43 16 0 <br>
87 44 16 0 <br>
88 45 16 0 <br>
89 46 16 0 <br>
90 47 16 0 <br>
91 48 16 0 <br>
92 49 16 0 <br>
93 50 16 0 <br>
94 51 16 0 <br>
95 52 16 0 <br>
{}button will do it for you.