sortコマンドのバージョンによる差異

古いsortコマンドのオプション、"+N"(Nは数値)が気が付いたらなくなっていた。そのため、qmailanalogのスクリプトをそのまま流用した場合エラーになったのだった。

古いsortコマンド

$ echo "aaa bbb" | sort +1
aaa bbb
$ sort --version
sort (coreutils) 5.2.1
Written by Mike Haertel and Paul Eggert.

Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[参考訳]
これはフリーソフトウェアです. コピーの条件についてはソースをお読みください.
市場性及び特定目的適合性の如何によらず, いかなる保証もありません.
$ cat /etc/redhat-release
CentOS release 4.4 (Final)
$

新しいsortコマンド

$ echo "aaa bbb" | sort +1
sort: オープン失敗: +1: そのようなファイルやディレクトリはありません
$ sort --version
sort (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.
$ cat /etc/redhat-release
CentOS release 5.2 (Final)
$

結局は、2列目でソートしたい場合、"+1"ではく、"-k 2"とするとよい。

$ echo "aaa bbb" | sort -k 2
aaa bbb
$

このネタ、wikipediaに載っていたのがすごい。

http://ja.wikipedia.org/wiki/Sort_(UNIX)