I have an input file that looks like this (the first column is the number of the place, and the second is the account, which should increase over time):
1 0 1 2 1 6 1 7 1 7 1 8 1 7 1 7 1 9 1 9 1 10 1 10 1 9 1 10 1 10 1 10 1 10 1 10 1 10 1 9 1 10 1 10 1 10 1 10 1 10 1 10
and I would like it to be like this (the number of substitutes decreased with the previous count):
1 0 1 2 1 6 1 7 1 7 1 8 1 8 1 8 1 9 1 9 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10
I try to use awk for this, but stumble with getline, since I cannot figure out how to reset the line number (NR?), So it will read each line and the next line, not two lines at a time. This is the code that I still have, any ideas?
awk '{a=$1; b=$2; getline; c=$1; d=$2; if (a==c && b<=d) print a"\t"b; else print c"\t"d}' original.txt > fixed.txt
Also, this is the result that I am currently getting:
1 0 1 6 1 7 1 7 1 9 1 10 1 9 1 10 1 10 1 9 1 10 1 10 1 10
awk getline
suegene
source share