Skip to content
Advertisement

Simple sorting in linux

I’m quite new to linux, and I can’t quite get to understand sorting. I need to sort a long file by column 4 and then column 5, ignoring the first line. The catch is, there are two separators – ‘.’ and ‘,’ – I don’t know how to make sort command to include both of them. I guess it has to be sorted by the column that has “3” in the first line, and then in the second sort by the column that has “5” in the second line. And the second thing is I don’t know how to keep the first line intact. Worth noting I can’t change all ‘,’ into ‘.’, it has to stay intact. And I can’t just remove the first line with tail or head, it has to stay.

This is the text:

JavaScript

Advertisement

Answer

I’m not sure if I understand the problem: in order to sort on columns 4 and 5 numerically, you can simply say:

JavaScript
  • -t, says to use a comma as a column separator
  • -k4,5 says to sort, based on columns 4 and 5
  • -n says to sort numerically

Remarks:

  • As far as the hyphen concerns: as it’s no part of the sorting columns, why bother about it?
  • As far as the column headers are concerned: due to the type of sorting, a letter comes in front of any number, so the column headers stay headers, so again why bother about it?
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement