ファイルを数値順に並べ替える

ファイルを数値順に並べ替える

重複の可能性:
数値順に並べられたファイルのリスト

最後のフィールドの番号で並べ替えるにはどうすればよいですか?私は前に試しましたsort -t ' ' -k9,10n

-rw-r--r-- 1 root   root    440 May 14 08:52 test.txt.6
-rw-r--r-- 1 root   root    470 May 14 08:52 test.txt.8
-rw-r--r-- 1 root   root   2.6K May 14 08:52 test.txt.14
-rw-r--r-- 1 root   root    449 May 14 08:52 test.txt.7
-rw-r--r-- 1 root   root    434 May 14 08:52 test.txt.13
-rw-r--r-- 1 root   root    554 May 14 08:52 test.txt.4
-rw-r--r-- 1 root   root    426 May 14 08:52 test.txt.12
-rw-r--r-- 1 root   root   1.6K May 14 08:52 test.txt.5
-rw-r--r-- 1 root   root   7.2K May 14 08:52 test.txt.11
-rw-r--r-- 1 root   root    444 May 14 08:52 test.txt.3
-rw-r--r-- 1 root   root    927 May 14 08:52 test.txt.9
-rw-r--r-- 1 root   root    681 May 14 08:52 test.txt.15
-rw-r--r-- 1 root   root    427 May 14 08:52 test.txt.2
-rw-r--r-- 1 root   root    458 May 14 08:52 test.txt.16
-rw-r--r-- 1 root   root   2.4K May 14 08:52 test.txt.10
-rw-r--r-- 1 root   root    423 May 14 08:52 test.txt.17
-rw-r--r-- 1 root   root    424 May 14 08:52 test.txt.1

ベストアンサー1

さて、問題のいくつかは、-t ' '区切り文字が折り畳まれていないため、9番目の列のサイズが4文字で3文字が空であることです。それを削除すると、希望の折りたたみスペースが作成されます。他の人が言ったように、問題の別の部分は、フィールドが数字ではないということです。幸いなことに、バージョン番号とよく似ており、-Vバージョンsort()を使用してソートできます。また、連続した場合(例:1-17、欠落なし)、他のスレッドで述べたように中括弧を使用できます(test.txt.{1..17})。

ls -l | sort -Vk9

echo test.text.{1..17}

おすすめ記事