I’m playing with awk and I’m trying to swap the first two fields of a file, like so:
awk -F : '/cjares/{temp=$1; $1=$2; $2=temp; print}' /etc/passwd
However, the output is not right. These are the two outputs, one without swapping the fields, the second after swapping the fields:
x cjares 3158 115 Caleb Timothy Jares,256 Avery Hall,2-7763 /home/ugrad/cjares /bin/tcsh
cjares:x:3158:115:Caleb Timothy Jares,256 Avery Hall,2-7763:/home/ugrad/cjares:/bin/tcsh
It replaces all semicolons with spaces.
In awk, the default output field separator (OFS) is a space ” “. You can change it: