sipcalc can do this - to do this right is not trivial as it requires
parser with lookahead or batracking. The shortening rules are designed
to be smart not simple for parsers.
sipcalc $(echo "ipv6 Thu Nov 16 00:05:34 PST 2017
[2603:01c2:1800:a8c0:0000:0000:0000:0001] foo bar baz" | sed
's/.*\[\([^]][^]]*\)\].*/\1/')|awk '/Compressed address/ {print $4}'
2603:1c2:1800:a8c0::1
if you want to filter the line you could wrap it in bash or insert the
sipcal call into the awk to keep/print the text around.
If you could youse perl:
perl -e 'use Net::IP; my $ip = new Net::IP
("2603:01c2:1800:a8c0:0000:0000:0000:0001",6); $ip = $ip->short();
print ($ip."\n");'
2603:1c2:1800:a8c0::1
Tomas
On Thu, 2017-11-16 at 00:09 -0800, Russell Senior wrote:
> Can anyone suggest a nice unix pipeline filter using lightweight
> tools
> (no python) to output an ipv6 address in reduced format. That is,
> with
> the extra zeros removed and colons condensed according the normal
> ipv6
> rules. Bonus for an example that leaves timestamps unscathed. In my
> case, the ipv6 address is inside square brackets. 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
>
>
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug