Swap first and second columns in a CSV file
Here you go:
awk -F, '{ print $2 "," $1 }' sampleData.csv
Because default delimiter is space/tab. Not comma. Taking your original code, and adding a -F,
solves it.
$ awk -F, ' { t = $1; $1 = $2; $2 = t; print; } ' /tmp/2016_logins.csv
day num_logins
2016-07-01 253
2016-07-02 127
$
Stripping it down to {$0=$2" "$1}1
gets same result.
$ awk -F, '{$0=$2" "$1}1' /tmp/2016_logins.csv
day num_logins
2016-07-01 253
2016-07-02 127
$