Case-Sensitive GNU sort

GNU sort appears to be producing case-insenstive output all the time, no matter what you use for the case-insenstive switch. Turns out there’s a little more going on behind the scenes you need to know.

Had something unexpected happen while using sort the other day: it behaved differently on two different systems.

In a nutshell, I went to go sort data that looked like this:
xyz
CAT
abc

The correct answer, due to case-sensitifivity, should have been:
CAT
abc
xyz

This, by the way is what Cygwin happens to produce.

Instead I was getting the case-insensitve answer:
abc
CAT
xyz

And while the sort program had a case-insenstivive switch, -f, it always seemed to be applied.

I checked for a command alias. None.

I tried a negation value, -f-, and that did nothing for me.

Eventually I figured out that the issue was with the locale specified in the environment variables.

If LC_ALL=en_US, then I got a case-insentive order, no matter what. The solution was to change it to LC_ALL=C to get the case-sensitive version.

As GNU allows explicitly for case-insensitivity, I really wish they’d also explicitly allow for case-sensitivy.

This seems to trip up a lot of people, judging by the number of posts out there about it.

OS X: Batch Rename from GUI

This is the third time I’ve had to go hunting how to enable batch filename manipulations for OS X. Now I’m documenting it so I don’t have to hunt this down again.

I keep forgetting about this trick, so I thought I’d post it in the event I have to ever do it again.

Part of the problem with a graphical GUI is that it’s very difficult to rename files in batches, for instance, prepending some text to a group of files.  This kind of thing is fairly trivial at the command line.

Apple has a facility to do this, but as it’s not something a regular user does often, it’s not enabled by default.  Here’s how to get all kinds of additional functionality out of OS X.

1) Open /Applications/AppleScript

2) Turn on Show Script Menu in menu bar

3) Optional: turn on GUI scripting, show library scripts, and choose where to show them.

You’ll notice up near the time in the menu bar a black scroll has appeared.

All the batch renaming and filename twiddling stuff is under the Finder Scripts.

UPDATE 19-Dec-2009: Upgrading to Snow Leopards deletes some useful scripts, specifically the Finder Scripts.

UPDATE 31-Aug-2010: The scripts live in “/Library/Scripts/Finger Scripts” and are

  • Add to File Names.scpt
    md5 4b0cd899acb19b5fc62ef2049d81a933 – 18114 bytes
  • Change Case of Item Names.scpt
    md5 af7429228be4d0e1a096092af5341c52 – 17808 bytes
  • Replace Text in Item Names.scpt
    md5 716493cab1c569953a7f40d76ed9a1f7 – 24328 bytes