BEGIN { FS = ","; # Initialize the field separator. OFS = ","; # Initialize the output field separator. } NF==4 { if ($3=="?") {$3=($2+$4)/2.0} if ($2 > $4) {tmp=$2; $2=$4; $4=tmp;} print $0 }