File: nut-dumpdiff.sh

package info (click to toggle)
nut 2.8.4%2Breally-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,720 kB
  • sloc: ansic: 132,030; sh: 17,256; cpp: 12,566; makefile: 5,646; python: 1,114; perl: 856; xml: 47
file content (35 lines) | stat: -rwxr-xr-x 1,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash

# This script is intended to simplify comparison of NUT data dumps,
# such as those collected by drivers with `-d 1` argument, or by
# the `upsc` client, ignoring irrelevant variations (e.g. numbers).
#
# TODO: Make more portable than bash and GNU toolkits
#
# Subject to same license as the NUT Project.
#
# Copyright (C)
#	2022 Jim Klimov <jimklimov+nut@gmail.com>
#

if [ $# = 2 ] && [ -s "$1" ] && [ -s "$2" ]; then
    echo "=== $0: comparing '$1' (-) vs. '$2' (+)" >&2
else
    echo "=== $0: aborting: requires two filenames to compare as arguments" >&2
    exit 1
fi

# Pre-sort just in case:
DATA1="`sort -n < "$1"`"
DATA2="`sort -n < "$2"`"

# Strip away same-context lines,
# and lines with measurements that are either decimal numbers
# or multi-digit numbers without a decimal point (assuming
# differences in shorter numbers or counters may be important)
diff -bu <(echo "$DATA1") <(echo "$DATA2") \
| grep -E '^[+-][^+-]' \
| grep -vE '^[^:]*(power|load|voltage|current|frequency|temperature|humidity): ([0-9][0-9]*|[0-9][0-9]*\.[0-9][0-9]*)$'

# Note: up to user to post-filter, "^driver.version.*:"
# may be deemed irrelevant as well