Try something like: awk 'NR%2{if(p!=$2){v=$1; p=$2}$1=v}1' FS=, OFS=, file This tests if `$2` has changed and substitutes `$1` on every odd line with the same value for every `$2`