ncomm started as helper to compare lists of installed packages of more than two systems or dates on OpenWrt but turned out to be usefull in other contexts too.

ncomm
#!/usr/bin/awk -f
# ncomm-1565083172
BEGIN {
	if(ARGC<2) {
		print "usage: ncomm list_1 ... list_N" >"/dev/stderr"
		exit(1)
	}
	for(i=1;i<ARGC;i++) {
		print s ARGV[i]
		s=s"| "
		while((rc=getline < ARGV[i])>0) { P[$0]++ ; f[$0,i]++ }
		if(rc<0) {
			print "ncomm: read error in file: "ARGV[i] >"/dev/stderr"
			exit(2)
		}
	}
	print s
	c="sort | cut -d/ -f2-"
	for(i in P) {
		printf i"/" | c
		for(n=1;n<ARGC;n++) printf f[i,n]?"+ ":"· " | c
		print i | c
	}
	close(c)
}

:!: The sorting is done in a decorate-sort-undecorate triple jump using / to separate decoration and data. To use data including / this needs o be changed to a different character or the whole way of sorting has to be changed to e.g. sort an index array only, so this separator gets futile. --- yeti 2018/03/26 16:31 GMT

$ cat test2.txt 
0
2
4
6
8
$ cat test3.txt 
0
3
6
9
$ cat test5.txt 
0
5
$ ncomm test2.txt test3.txt test5.txt 
test2.txt
| test3.txt
| | test5.txt
| | | 
+ + + 0
+ · · 2
· + · 3
+ · · 4
· · + 5
+ + · 6
+ · · 8
· + · 9

...with lists of Devuan packages and filtering for init related stuff:

$ ncomm packages.pi1-0 packages.pi2-0 packages.pi3-0 | awk 'NR<5||/init/'
packages.pi1-0
| packages.pi2-0
| | packages.pi3-0
| | | 
· · + init 1.24+devuan1.0 
+ + · init 1.46+devuan1.0 
· · + initramfs-tools 0.120+deb8u2 
+ · · initramfs-tools 0.130 
+ · · initramfs-tools-core 0.130 
+ + + initscripts 2.88dsf-59.3+devuan2 
· · + init-system-helpers 1.24+devuan1.0 
+ + · init-system-helpers 1.46+devuan1.0 
+ + + sysvinit 2.88dsf-59.3+devuan2 
+ + + sysvinit-core 2.88dsf-59.3+devuan2 
· · + sysvinit-utils 2.88dsf-59.2+devuan2 
+ + · sysvinit-utils 2.88dsf-59.3+devuan2 
  • Last modified: 2019/08/06 18:14
  • by yeti