I would like to replace the values 3 and 4 for 0 and 1, respectively, in all fields in the first, third, fiveth row and so on until the end of the following data set:
2 4 3 0
2 4 3 0
3 0 4 4
3 0 4 4
4 2 4 3
4 2 4 3
2 3 4 2
2 3 4 2
So, the desired result is:
2 1 0 0
2 4 3 0
0 0 1 1
3 0 4 4
1 2 1 0
4 2 4 3
2 0 1 2
2 3 4 2
I'm using the following code to do that:
awk '{for (i = 1; i <= NR; i=(i+2))
if($i == 3) {$i = 0}
if($i == 4) {$i = 1}
}
END {print $0}' b.temp
However, the output for this code is only the values in the last row of b.temp file (2 3 4 2).
How can I do that? The code needs to that for any numer of rows and fields. The solution can be in awk, sed or other alternative in shell script.
Thanks in advance