Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのようなリストを持っています-
2009-96 2010-100 2010-101 2010-97 2010-98 2010-99 2009-99a 2011-102
数字を正しい順序で並べ替えて、年が異なる場合は最初の4桁(年)で並べ替え、それ以外の場合は後の数字で並べ替えるにはどうすればよい-ですか?
-
私が欲しい正しい出力は-
2009-96 2009-99a 2010-97 2010-98 2010-99 2010-100 2010-101 2011-102
sortコマンドラインオプションが異なる場合があるため、バージョンによって異なりますが、私のシステムではsort -t - -k 1,1n -k 2,2n <filename>機能します。
sort
sort -t - -k 1,1n -k 2,2n <filename>
GNUソート(Linuxではstd)の場合:
sort -t'-' -n
sort行を並べ替えるので、@ dimbaの回答に示されているように、スペース区切り文字を\n使用して前後に変換します。tr
\n
tr