I know there are tons of sorting questions on here, but I'm unable to resolve my use case.

I am trying to sort a list in R (on Ubuntu 16.04) and am at my wits end! I've been trying to mess with the LC_ALL=C and collate settings and can get results to sort differently, but I'm unable to get the result I need. This is what I need:

2014_Actual / 2014_Target / 2014_Percent / 2015_Actual / 2015_Target / 2015_Percent

The trick I use in windows is to delete the underscore, so: 2014_Actual / 2014_Target / 2014Percent / 2015_Actual / 2015_Target / 2015Percent, which is acceptable to my users. But obviously this doesn't work in Linux since it ignores the underscore.

Does anybody have any ideas on how I could get the above mentioned sort order at the LC_ALL level?

Thanks in advance.

EDIT: Adding clarity: the problem is that when I sort the above in Linux, it ignores the underscore and gives:
2014_Actual / 2014Percent / 2014_Target / 2015_Actual / 2015Percent / 2015_Target

  • 1
    this is within R, you're saying? – Jeff Schaller Jun 5 '17 at 16:15
  • is: mv 2014_Target 2014_target; mv 2015_Target 2015_target acceptable? – Jeff Schaller Jun 5 '17 at 16:18
  • If this is a question about how to write it in R, that's more suited to SO than to U&L, is it not? – DopeGhoti Jun 5 '17 at 16:24
  • Correct @JeffSchaller, it's within R... but the Linux sort environment comes through. – Amit Kohli Jun 5 '17 at 16:25
  • 1
    what are you doing in R to call out to the Linux environment? (and is renaming Target to target acceptable?) – Jeff Schaller Jun 5 '17 at 16:43

I’m not sure I understand the entirety of your question, but if I were doing that in Unix, I would do

sed -e 's/Actual/1Actual/' -e 's/Target/2Target/' -e 's/Percent/3Percent/' |
    sort |
    sed -e 's/1Actual/Actual/' -e 's/2Target/Target/' -e 's/3Percent/Percent/'
  • GENIUS!!!!! RENAME SORT RENAME......... DUuuuuuuuuuuuuuuuuuh omg I want to die – Amit Kohli Jun 5 '17 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.