PDA

View Full Version : Howto Swap the Order of Columns in a CSV in bash



nkululeko
20-Mar-2012, 10:17
Hi all

I need help to reorder my csv columns .
eg name uid surname to uid name surname .

mikewillis
20-Mar-2012, 11:06
Like this?

me@mine:/tmp> cat blah
name,uid,surname
me@mine:/tmp> IFS=,; while read -r f1 f2 f3 ;do echo "${f2},${f1},${f3}" ;done <blah
uid,name,surname