bash
+ awk
:
i=0;
for n in 2 5; do
awk -v n="$n" -v iter=$((++i)) \
'iter == 1{
if ($1 > n) { $1-- } else if ($1 == n) { next }
}
iter > 1{
if ($1 + 1 == n){ next } else if ($1 >= n) $1--
}1' inp_file > tmp_inpfile && mv tmp_inpfile inp_file
done
O conteúdo final de inp_file
:
7 1 2
5 3 1
6 2 1
2 2 1
1 1 1