Hacker News new | ask | show | jobs
by tzs 2209 days ago
Can it output fields in an order other than their input order? That's the one thing I regularly wish cut could do. I would like the output of the second cut below to be "3,1", not "1,3".

  $ echo "1,2,3,4,5" | cut -d , -f 1,3
  1,3
  $ echo "1,2,3,4,5" | cut -d , -f 3,1
  1,3
2 comments

Yes:

  $ echo "1,2,3,4,5" | choose -f , 2 0
  3 1
  $ echo "1,2,3,4,5" | choose -f , 2:0
  3 2 1
Note that the indexing starts with 0, "-d" is "-f", and a range is denoted by ":" instead of "-" which is used for indexing from the end.

    awk -F, '{print $3","$1}'