config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 9078f756768e04a0f379d367b5e5560ce11e47cc
parent c81bde1dd43a6e732e9266a4d19c1557dff2e1a1
Author: Jacob R. Edwards <n/a>
Date:   Sat,  3 Dec 2022 12:00:24 -0600

Add notin, a script to show lines not in files

This useful little script is pretty simple; it reads the lines from
the standard input and removes them as it comes across them in the
given files finally printing whichever remain at the end.

Diffstat:
Alocal/bin/bin/notin | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/local/bin/bin/notin b/local/bin/bin/notin @@ -0,0 +1,35 @@ +#!/usr/bin/awk -f +# Copyright 2022 Jacob R. Edwards +# Only print lines from stdin that don't appear in the given files + +BEGIN { + if (ARGC <= 1) { + error = "usage: notin file [...]" + exit + } + while ((s = getline line < "/dev/stdin" > 0)) { + arr[++i] = line; + map[line] = i; + } + if (s < 0) { + error = "Unable to read from stdin" + exit + } +} + +{ + if ($0 in map) { + delete arr[map[$0]] + delete map[$0] + } +} + +END { + if (error) { + print error > "/dev/stderr" + exit 1 + } + for (i = 1; i <= length(arr); ++i) { + if (arr[i] in map) + print arr[i]; } +}