On Thu, Nov 16, 2017 at 12:09 AM, Russell Senior <[email protected]> wrote: > Can anyone suggest a nice unix pipeline filter using lightweight tools > (no python) to output an ipv6 address in reduced format.
Why not python/perl/ruby/etc.? If only given an IPv6 address, this would work: echo '2603:01c2:1800:a8c0:0000:0000:0000:0001' | sed -re 's/:0+/:/g;s/::+/::/g' Outputs: 2603:1c2:1800:a8c0::1 > For example: > > ipv6 Thu Nov 16 00:05:34 PST 2017 [2603:01c2:1800:a8c0:0000:0000:0000:0001] > foo bar baz > > should become: > > ipv6 Thu Nov 16 00:05:34 PST 2017 [2603:1c2:1800:a8c0::1] foo bar baz A bash solution to preserve date/time stamps: echo 'ipv6 Thu Nov 16 00:05:34 PST 2017 [2603:01c2:1800:a8c0:0000:0000:0000:0001] foo bar baz' | tr '][' '\t' | while IFS=$'\t' read a b c ; do b=$(<<< "$b" sed -re 's/:0+/:/g;s/::+/::/g') echo "$a[$b]$c" done Outputs: ipv6 Thu Nov 16 00:05:34 PST 2017 [2603:1c2:1800:a8c0::1] foo bar baz But that is a very specific solution. Regards, - Robert _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
