commr

Crates.iocommr
lib.rscommr
version0.1.0
sourcesrc
created_at2024-03-04 22:13:31.110384
updated_at2024-03-04 22:13:31.110384
descriptionRust version of comm
homepagehttps://github.com/kyclark/commr
repositoryhttps://github.com/kyclark/commr
max_upload_size
id1162349
size77,036
Ken Youens-Clark (kyclark)

documentation

README

commr

Rust version of comm

Synopsis

commr reads two files and reports the lines of text that are common to both and the lines that are unique to each. These are set operations where the common lines are the intersection of the two files and the unique lines are the difference. If you are familiar with databases, you might also consider these as types of join operations.

$ commr --help
Rust version of comm

Usage: commr [OPTIONS] <FILE1> <FILE2>

Arguments:
  <FILE1>  Input file 1
  <FILE2>  Input file 2

Options:
  -1                                  Show column 1
  -2                                  Show column 2
  -3                                  Show column 3
  -i, --insensitive                   Case-insensitive comparison of lines
  -d, --output-delimiter <DELIMITER>  Output delimiter [default: "\t"]
  -h, --help                          Print help
  -V, --version                       Print version

The output is three columns of text separated by the --output-delimiter:

  1. The lines unique to file1
  2. The lines unique to file2
  3. The lines common to both files

For instance, given these files:

$ cat tests/inputs/file1.txt
a
b
c
d
$ cat tests/inputs/file2.txt
B
c

The default output will be:

$ commr tests/inputs/file1.txt tests/inputs/file2.txt
	B
a
b
		c
d

The output again with a delimiter to make it easier to see the columns:

$ commr tests/inputs/file1.txt tests/inputs/file2.txt -d='--->'
--->B
a
b
--->--->c
d

One of the input files may be STDIN (standard in) as indicated by a dash (-):

$ commr tests/inputs/file1.txt - -d='--->' <tests/inputs/file2.txt
--->B
a
b
--->--->c
d

Both inputs may not be STDIN:

$ commr - -
Both input files cannot be STDIN ("-")

Use the -i|--insensitive flag for case-insensitive comparisons:

$ commr tests/inputs/file1.txt tests/inputs/file2.txt -i
a
		b
		c
d

Use -1 to see just the first column:

$ commr -1 tests/inputs/file1.txt tests/inputs/file2.txt
a
b
d

Use -2 to see just the first column:

$ commr -2 tests/inputs/file1.txt tests/inputs/file2.txt
B

Use -3 to see just the first column:

$ commr -3 tests/inputs/file1.txt tests/inputs/file2.txt
c

Use any combination of -1, -2, or -3 to show columns:

$ commr -d "|" -13 tests/inputs/file1.txt tests/inputs/file2.txt
a
b
|c
d

Rationale

The BSD/GNU versions of comm use the -1, -2, and -3 flags to suppress the printing of the columns. This Rust version inverts the meanings to mean these columns should be shown. Like the wc program, the default will be to show all the columns unless the user indicates which columns they wish to see.

Author

Ken Youens-Clark kyclark@gmail.com

Commit count: 0

cargo fmt