このコマンドがuniqの数に基づいてソートされないのはなぜですか?

このコマンドがuniqの数に基づいてソートされないのはなぜですか?

私のログには次のような行があります。

2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.11:61618) is not a trusted source.
2015/11/02-07:55:40.515 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.11:51836) is not a trusted source.
2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.10:61615) is not a trusted source.
2015/11/02-07:55:40.515 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.10:51876) is not a trusted source.
2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.10:61614) is not a trusted source.
2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.15:61614) is not a trusted source.
2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.15:61618) is not a trusted source.
2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED.  (10.10.10.15:61613) is not a trusted source.

そのため、各固有IPの数(ソート)を取得するために次のコマンドを試しました。

grep ERR_AUTHORIZATION_REQUIRED file.log | awk '{print $6}' | cut -s -d ':' -f1 | tr -d '(' | sort | uniq -c

私が得た結果は次のようになります。

3 10.10.10.10
2 10.10.10.11
3 10.10.10.15

したがって、適用する前にIPをソートするのと似ていますが(コマンドが与えられた場合は意味があります)、コマンドを変更するとuniq -c各IPに数が印刷されます。uniqsort1

ベストアンサー1

uniqマンページから:

DESCRIPTION
     Discard all but one of successive identical lines from INPUT (or standard input), writing to OUTPUT (or standard output).

ここで重要な言葉は「永続的」です。ストリーム内の任意の時点で重複項目を検索せずに、直後に続く重複項目のみを検索します。並べ替えると、すべての重複項目が互いに隣接して配置され、削除(および計算)されます。

おすすめ記事