私がソートしたいデータです。ただし、sort
数値を文字列として処理すると、データは期待どおりに並べ替えられません。
/home/files/profile1
/home/files/profile10
/home/files/profile11
/home/files/profile12
/home/files/profile14
/home/files/profile15
/home/files/profile16
/home/files/profile2
/home /file/profile3
/main/file/profile4
/master/file/profile5 /master /file/profile6
/ master/file/profile7 /master/file/profile8 /master/file /profile9
私はそれを次のようにソートしたいと思います。
/home/files/profile1
/home/files/profile2
/home/files/profile3
/home/files/profile4
/home/files/profile5
/home/files/profile6
/home/files/profile7
/home/files/profile8
/home /file/profile9
/home/file/profile10 /home/ file/profile11 /
home /file/profile12 /home/file/profile14 /home/file/profile15 /home/file /profile16
Bashスクリプトでこれを行うための良い方法はありますか?ここではRubyやPythonスクリプトは使用できません。
ベストアンサー1
これは次のようによく似ています。この問題。問題は、ソートしたい英数字フィールドがあり、-n
それを賢明に処理しないが、バージョンsort(-V
)は処理することです。したがって、以下を使用してください。
sort -V
この機能は現在、GNU、FreeBSD、およびOpenBSDソート実装でサポートされています。