Tuesday, February 14, 2006

Lessons the hard way, Part IV

While wrapping up the finishing stages of the Oracle Applications Upgrade from you know where, I discovered the sort command works different on Solaris and Linux.

Take for example, a simple little directory listing:

jake$ cat sortit.txt
prodappl
prodappl/abm
prodappl/APPLSYS.env.tmp
prodappl/abm/11.5.0/admin
prodappl/APPSORA.env
prodappl/PROD.env
prodappl/abm/11.5.0
prodappl/abm/11.5.0/admin/driver
prodappl/APPLSYS.env
prodappl/abm/11.5.0/admin/driver/abmcon.drv


On Linux, I sort it:

jake$ cat sortit.txt | sort
prodappl
prodappl/abm
prodappl/abm/11.5.0
prodappl/abm/11.5.0/admin
prodappl/abm/11.5.0/admin/driver
prodappl/abm/11.5.0/admin/driver/abmcon.drv
prodappl/APPLSYS.env
prodappl/APPLSYS.env.tmp
prodappl/APPSORA.env
prodappl/PROD.env


On Solaris, same command:

woody# cat sortit.txt | sort
prodappl
prodappl/APPLSYS.env
prodappl/APPLSYS.env.tmp
prodappl/APPSORA.env
prodappl/PROD.env
prodappl/abm
prodappl/abm/11.5.0
prodappl/abm/11.5.0/admin
prodappl/abm/11.5.0/admin/driver
prodappl/abm/11.5.0/admin/driver/abmcon.drv


Hmm. I did a "man sort" and found my answer was to force a sort order using the -f flag.

3 comments:

Anonymous said...

Likely your locale settings. Check your environment.

Norman Brightside said...

Divine punishment for entering an additional seven characters ?

# sort sortit.txt

:-)

Steve said...

Get this - on Red Hat Enterprise Linux:

Start off with the default LANG setting:
> echo $LANG
en_US.UTF-8

> sort < sortit.txt
prodappl
prodappl/abm
prodappl/abm/11.5.0
prodappl/abm/11.5.0/admin
prodappl/abm/11.5.0/admin/driver
prodappl/abm/11.5.0/admin/driver/abmcon.drv
prodappl/APPLSYS.env
prodappl/APPLSYS.env.tmp
prodappl/APPSORA.env
prodappl/PROD.env


Now watch this:
> unsetenv LANG
> sort < sortit.txt
prodappl
prodappl/APPLSYS.env
prodappl/APPLSYS.env.tmp
prodappl/APPSORA.env
prodappl/PROD.env
prodappl/abm
prodappl/abm/11.5.0
prodappl/abm/11.5.0/admin
prodappl/abm/11.5.0/admin/driver
prodappl/abm/11.5.0/admin/driver/abmcon.drv