Help us understand the problem. What is going on with this article?

Linux基本コマンド sort diff uniq

sort

オプション

オプション 説明
-n 数字としてソートする
-t 区切り文字を指定
-k 何列目
-r 逆順

testファイルで確認

```
kuroda male tokyo 70
amy female tokyo 60
yoko male tochigi 80
hana female osaka 75
```

1. ソート

$ sort test 

amy female tokyo 60
hana female osaka 75
kuroda male tokyo 70
yoko male tochigi 80

2. 逆順でソート

$ sort -r test

yoko male tochigi 80
kuroda male tokyo 70
hana female osaka 75
amy female tokyo 60

3. 2列目でソート

$ sort -k 2 test

hana female osaka 75
amy female tokyo 60
yoko male tochigi 80
kuroda male tokyo 70

4. 数字でソート

$ sort -k 4 -n test

amy female tokyo 60
kuroda male tokyo 70
hana female osaka 75
yoko male tochigi 80

利用例

# ファイルサイズでsort
ls -la | sort -rk 5

uniq

ファイル内容をユニックにする、sortと合わせて利用が多い

オプション

オプション 説明
-c 重複数を集計
-i 大文字、小文字区別しない
$ cat uniq.txt
abc
123
abc
123

$ sort uniq.txt | uniq
123
abc

$ sort uniq.txt | uniq -c
2 123
2 abc

diff

```
$ diff -u file1 file2 # 見やすい形式
```

色付きで見る

```
$ brew install colordiff
$ colordiff -u file1 file2
```

関連

linuxのテキスト編集(vi, sed, tr, grepなど+xargs)まとめ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away