I have the following sequence,
N
H
CB
CB
CG1
CG2
C
O
N
H
CB
CB
CG
CD
.
.
.
and I would like to replace the first "CB" with "CA" when "CB" is repeated in line below, so as to end up with the following sequence
N
H
CA
CB
CG1
CG2
C
O
N
H
CA
CB
CG
CD
.
.
.
sed -E '$!N;s/^(CB)(\n\1)$/CA\2/'