05: Further explanation of `sort` #445

Open
mjones01 opened this Issue Sep 1, 2016 · 4 comments

Projects

None yet

4 participants

@mjones01
Contributor
mjones01 commented Sep 1, 2016

Currently in 05 sort and sort -n is introduced, however, on this dataset (downloaded from website link on 31 Aug 2016) both work the same, might want to consider explanation for this.

@iglpdc
Contributor
iglpdc commented Sep 1, 2016

Yep, I agree. By default, if you are ordering according to a numeric value you should always use sort -n. In this case, it doesn't matter because the numbers are properly prepended with some whitespace makes sort work as sort -n. But, I agree it's confusing...

@gdevenyi
Contributor

Hi, on this dataset, sort and sort -n do not produce the same results,

from https://github.com/swcarpentry/shell-novice/blob/gh-pages/_episodes/04-pipefilter.md:

> cat lengths.txt
  20  cubane.pdb
  12  ethane.pdb
   9  methane.pdb
  30  octane.pdb
  21  pentane.pdb
  15  propane.pdb
 107  total
> sort lengths.txt
 107  total
  12  ethane.pdb
  15  propane.pdb
  20  cubane.pdb
  21  pentane.pdb
  30  octane.pdb
   9  methane.pdb
> sort -n lengths.txt
   9  methane.pdb
  12  ethane.pdb
  15  propane.pdb
  20  cubane.pdb
  21  pentane.pdb
  30  octane.pdb
 107  total

This is on linux with GNU coreutils' version of sort.

Are you using another system?

@iglpdc
Contributor
iglpdc commented Sep 14, 2016

They produce the same result in the Macs (and maybe in Windows).

@shwina
Member
shwina commented Sep 16, 2016

Can confirm that both commands produce the same result on Macs. Macs don't use GNU sort by default. Maybe we should just recommend using the -n switch to sort numerically if it doesn't work without it (perhaps in a callout?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment