What we can do is transpose the columns to rows using the rs
utility originating from BSD Unix, then just sort
the rows (thus, effectively, sorting the columns of the original data), and then transpose again.
Firstly, note by the way that, in alphabetical order, it's: address, mobile-number, name. M is before N!
Step by step:
$ cat data
name ,adress ,mobile-number
Ane ,USA ,12121212
Joane ,England ,234234
$ rs -s, -C, -T < data
name ,Ane ,Joane ,
adress ,USA ,England ,
mobile-number,12121212,234234,
$ rs -s, -C, -T < data | sort
adress ,USA ,England ,
mobile-number,12121212,234234,
name ,Ane ,Joane ,
$ rs -s, -C, -T < data | sort | rs -s, -C, -T
adress ,mobile-number,name ,
USA ,12121212,Ane ,
England ,234234,Joane ,
$ rs -s, -C, -T < data | sort | rs -s, -S' ' -T
adress mobile-number name
USA 12121212 Ane
England 234234 Joane
Finally:
$ rs -s, -C, -T < data | sort | rs -s, -S' ' -T | sed -e 's/ \([^ ]\)/,\1/g'
adress ,mobile-number ,name
USA ,12121212 ,Ane
England ,234234 ,Joane
I did this on Ubuntu GNU/Linux, and first had to sudo apt-get install rs
.
name, address
in the input butaddress, name
in the output? Is that intentional? Please edit your question and clarify.name
should come aftermobile-number
by that logic. OP can you please clarify/edit the question,