Like comm(1), but for any number of files

ncomm

ncomm is like comm, but for any number of files, not just two files.

Installation

go install github.com/ucarion/ncomm

Usage

To compare the contents of two (sorted) files a and b, run:

ncomm a b

The output will be exactly the same as comm a b. Unlike comm, you can pass additional files. To compare sorted files a, b, c, d, run:

ncomm a b c d

Whereas ncomm a b gave you three columns of output, ncomm a b c d will produce 15 columns; each column represents a different combination of a, b, c, or d that a line might appear in.

To make it more obvious what the columns mean, use --show-header for a legend:

ncomm --show-header a b c d
x---	-x--	xx--	--x-	x-x-	-xx-	xxx-	---x	x--x	-x-x	xx-x	--xx	x-xx	-xxx	xxxx	
[...]

You can also run ncomm --help for detailed information:

usage: ncomm [
   
    ] files...

like comm(1), but for any number of files

        --show-header    output a header to help explain what each column represents
    -h, --help           display this help and exit


   

Example

Here's a more fleshed-out example of how ncomm can start to be useful in the real world. In examples in this repo, there's a set of files:

  • eu.txt lists members of the European Union
  • nato.txt lists members of the North Atlantic Treaty Organization
  • oecd.txt lists members of the Organisation for Economic Co-operation and Development

All three of these are clubs of countries. With ncomm, you can see how they overlap:

ncomm --show-header ./examples/eu.txt ./examples/nato.txt ./examples/oecd.txt
x--	-x-	xx-	--x	x-x	-xx	xxx	
	Albania
			Australia
				Austria
						Belgium
		Bulgaria
					Canada
			Chile
			Colombia
			Costa Rica
		Croatia
						Czech Republic
						Denmark
						Estonia
				Finland
						France
						Germany
						Greece
						Hungary
					Iceland
				Ireland
			Israel
						Italy
			Japan
			Korea
						Latvia
						Lithuania
						Luxembourg
Malta
			Mexico
	Montenegro
						Netherlands
			New Zealand
	North Macedonia
					Norway
						Poland
						Portugal
Republic of Cyprus
		Romania
			Slovak Republic
		Slovakia
						Slovenia
						Spain
				Sweden
			Switzerland
					Turkey
					United Kingdom
					United States

The first row comes from --show-header, and makes it a bit easier to figure out what each column represents. For instance, we can see that the 5th columns has a header x-x, indicating lines that are in the 1st and 3rd file but not the 2nd. In our example, that represents countries that are in the EU and OECD, but not NATO. We can extract just those countries with a bit of cut, and then remove blank lines with grep:

ncomm ./examples/eu.txt ./examples/nato.txt ./examples/oecd.txt | cut -s -f 5 | grep .
Austria
Finland
Ireland
Sweden

Alternatively, if we wanted to count how many countries fell into each of the seven possible "buckets", you could count how many tabs there are on each line, and then count how many lines have that number of tabs:

ncomm ./examples/eu.txt ./examples/nato.txt ./examples/oecd.txt | awk -F$'\t' '{print NF}' | sort | uniq -c
   2 1
   3 2
   4 3
  11 4
   4 5
   6 6
  17 7

As before, you could use --show-header to make sense of what each column number means.

Owner
Ulysse Carion
( ˘▽˘)っ♨
Ulysse Carion
Similar Resources

a leaderboard system that can run on any Internet enabled device.

hacktoberfest-leaderboard a leaderboard system that can run on any Internet enabled device. How it works The app updates the leaderboard on README.md

Nov 1, 2021

An ease to use finit state machine golang implementation.Turn any struct to a fsm with graphviz visualization supported.

go-fsm An ease to use finit state machine golang implementation.Turn any struct to a fsm with graphviz visualization supported. usage import github.co

Dec 26, 2021

Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA

Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA

Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA

Feb 27, 2022

Renda is a go library that repeatedly executes any processes

Renda is a go library that repeatedly executes any processes.

Feb 7, 2022

Implementation of the Feynman algorithm to solve any problem!

Feynman Algorithm Allegedly coined in jest by Murray Gell-Mann to describe Richard Feynman's incredible problem solving ability, this simple algorithm

Mar 16, 2022

Get user-like access to VirtualBox VMs from Go code.

#Vboxgo Get user-like access to VirtualBox VMs from Go code. This library wraps some define-tainted VirtualBox SDK functions, making it possible to ge

Oct 25, 2021

Assembly syntax that makes you feel like you're writing code in a high-level language.

shasm Assembly syntax that makes you feel like you're writing code in a high-level language. Shasm is not an Assembler. Shasm simply compiles Shasm sy

Jun 5, 2021

go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top go-playground-validator.

Go Playground Converter go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top in go-playground

Dec 9, 2022

Names things like they're action movies from the mid 90s.

thing-namer Names things like they're action movies from the mid 90s. Installing You know the drill. go get github.com/Unquabain/thing-namer Building

Nov 6, 2021
Related tags
Jan 4, 2022
Go code to generate Captcha letters for any TrueType font format files.

Go code to generate Captcha letters for any TrueType font format files. The code can be modified for the background and font colors. The code can be easily upgraded for distorted and rotated letters. These generated lettes can be stiched together to make captcha string.

Jan 31, 2022
Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.

Codename an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superheroe like" codenames, consisting of a random combinatio

Dec 11, 2022
Numtow - Golang number to words converter

numtow golang library to convert number to words. Supported languages: kazakh, e

Dec 31, 2022
Allows verifying client's phone number

hone verification module for Elling - Elytrium Billing

Jun 4, 2022
Print debugging, but a little bit nicer

testlog Print debugging, but a little bit nicer. The use case this is primarily designed for is effectively debugging problematic, flaky tests.

Oct 11, 2021
Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Dec 24, 2022
Solution to elevator test problem but this time recursive and in go

Synopsis A multi-floor building has a Lift in it. People are queued on different floors waiting for the Lift. Some people want to go up. Some people w

Nov 8, 2021
Generic-list-go - Go container/list but with generics

generic-list-go Go container/list but with generics. The code is based on contai

Dec 7, 2022
Terrible Idea. Elm but in Go
Terrible Idea. Elm but in Go

Elmgo .' '.' `. _.-| o | o |-._ .~ `.__.'.__.'^ ~. .~ ^ / \ ^ ~. \-._^ ^| | ^_.-/ `\ `-._ \___/ ^_.-' /'

Feb 9, 2022