LoginSignup
0
1

More than 5 years have passed since last update.

リストAに書かれた内容からリストBの各行を除いたものを取得する

Posted at

とい

リストAに書かれた内容からリストBの各行を除いたものを取得せよ。

こたえ

$ cat A.txt
1111
2222
3333
4444
5555
$ cat B.txt
1111
3333
$ cat a.txt b.txt | sort | uniq -u
2222
4444
5555

uniqコマンドは重複行を削除するコマンド。
あえて重複させて-uオプションで除外してやればよい。
ただし、sortされていないといけないのでsortコマンドをはさむ。

オプション 説明
-u, --unique 重複行を削除する(ユニークな行だけ出力)

参考

Linuxコマンド集 - 【 uniq 】 ソート済みのファイルから重複した行を削除する:ITpro http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230918/

uniq コマンド | コマンドの使い方(Linux) | hydroculのメモ https://hydrocul.github.io/wiki/commands/uniq.html

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1