Simple Sand Samples |
説明のないとってもシンプルなサンプルプログラム集
COBOL | awk | C言語 | D言語 | GO言語 | Lua | Vim |
bash | Perl | Gauche | Clojure | CLISP | EmacsLisp | VimScript |
tcsh | Ruby | Groovy | Java | C# | VBScript | JavaScript |
Io言語 | Python | Erlang | Scala | VB.NET | Excel/VBA | PHP |
Tcl | Haskell | OCaml | PowerShell | Windows | Unix/Linux |
Linuxコマンド > sort ソート
|
|
~$ cat hoge.txt ※タブ区切りテキスト
1 dog field3-3
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
10 ice field3-4
~$
1 dog field3-3
10 ice field3-4
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
~$
1 dog field3-3
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
10 ice field3-4
~$
6 apple field3-10
3 banana field3-9
9 cat field3-8
1 dog field3-3
7 egg field3-7
2 fun field3-2
4 good field3-6
8 hot field3-5
10 ice field3-4
5 jam field3-1
~$
5 jam field3-1
6 apple field3-10
2 fun field3-2
1 dog field3-3
10 ice field3-4
8 hot field3-5
4 good field3-6
7 egg field3-7
9 cat field3-8
3 banana field3-9
~$
9 cat field3-8
8 hot field3-5
7 egg field3-7
6 apple field3-10
5 jam field3-1
4 good field3-6
3 banana field3-9
2 fun field3-2
10 ice field3-4
1 dog field3-3
7 egg field3-7
6 apple field3-10
2 fun field3-2
8 hot field3-5
4 good field3-6
5 jam field3-1
10 ice field3-4
3 banana field3-9
9 cat field3-8
1 dog field3-3
1 dog field3-3
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
10 ice field3-4
~$
指定なし(フィールド1文字列順)でソートする
~$ sort hoge.txt1 dog field3-3
10 ice field3-4
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
~$
数字順でソートする
~$ sort -n hoge.txt1 dog field3-3
2 fun field3-2
3 banana field3-9
4 good field3-6
5 jam field3-1
6 apple field3-10
7 egg field3-7
8 hot field3-5
9 cat field3-8
10 ice field3-4
~$
フィールドを指定してソートする(タブ区切りで2列目を指定)
~$ sort -k2 hoge.txt6 apple field3-10
3 banana field3-9
9 cat field3-8
1 dog field3-3
7 egg field3-7
2 fun field3-2
4 good field3-6
8 hot field3-5
10 ice field3-4
5 jam field3-1
~$
フィールドとバイト位置を指定してソートする(3列目の8バイト目)
~$ sort -k3.8 hoge.txt5 jam field3-1
6 apple field3-10
2 fun field3-2
1 dog field3-3
10 ice field3-4
8 hot field3-5
4 good field3-6
7 egg field3-7
9 cat field3-8
3 banana field3-9
~$
逆順にソートする
~$ sort -r hoge.txt9 cat field3-8
8 hot field3-5
7 egg field3-7
6 apple field3-10
5 jam field3-1
4 good field3-6
3 banana field3-9
2 fun field3-2
10 ice field3-4
1 dog field3-3
ランダムソートする
~$ sort -R hoge.txt7 egg field3-7
6 apple field3-10
2 fun field3-2
8 hot field3-5
4 good field3-6
5 jam field3-1
10 ice field3-4
3 banana field3-9
9 cat field3-8
1 dog field3-3