New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

05: Further explanation of `sort` #445

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

Comments

Projects
None yet
5 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

This comment has been minimized.

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

This comment has been minimized.

Contributor

gdevenyi commented Sep 14, 2016

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

This comment has been minimized.

Contributor

iglpdc commented Sep 14, 2016

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

@shwina

This comment has been minimized.

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?).

@aliceminotto

This comment has been minimized.

aliceminotto commented Nov 8, 2017

Wouldn't it be good to add a note or a comment in the lesson? Last time we had about 1/3 of the people with a red post it to ask why they were getting a different output than the instructor. I realized the pattern mac/linux users after checking on a couple of people. I guess since the instructor likely works on a specific OS s/he may no notice this before the actual carpentry.

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