2015-12-28 13:04:58 +00:00
|
|
|
# comm
|
|
|
|
|
|
|
|
> Select or reject lines common to two files. Both files must be sorted.
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Produce three tab-separated columns: lines only in first file, lines only in second file and common lines:
|
2015-12-28 13:04:58 +00:00
|
|
|
|
|
|
|
`comm {{file1}} {{file2}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Print only lines common to both files:
|
2015-12-28 13:04:58 +00:00
|
|
|
|
|
|
|
`comm -12 {{file1}} {{file2}}`
|
|
|
|
|
2016-05-09 14:17:43 +01:00
|
|
|
- Print only lines common to both files, reading one file from stdin:
|
2015-12-28 13:04:58 +00:00
|
|
|
|
|
|
|
`cat {{file1}} | comm -12 - {{file2}}`
|
|
|
|
|
2016-05-09 14:17:43 +01:00
|
|
|
- Get lines only found in first file, saving the result to a third file:
|
2015-12-28 13:04:58 +00:00
|
|
|
|
2016-07-22 21:24:06 +01:00
|
|
|
`comm -23 {{file1}} {{file2}} > {{file1_only}}`
|
2015-12-28 13:04:58 +00:00
|
|
|
|
2016-05-09 14:17:43 +01:00
|
|
|
- Print lines only found in second file, when the files aren't sorted:
|
2015-12-28 13:04:58 +00:00
|
|
|
|
2016-05-09 14:17:43 +01:00
|
|
|
`comm -13 <(sort {{file1}}) <(sort {{file2}})`
|