Skip to content

Instantly share code, notes, and snippets.

@nixomose
Created January 31, 2019 17:16
Show Gist options
  • Save nixomose/96a5a307629b5ce8d3abea7575c2ff82 to your computer and use it in GitHub Desktop.
Save nixomose/96a5a307629b5ce8d3abea7575c2ff82 to your computer and use it in GitHub Desktop.
#!/usr/bin/gawk -f
BEGIN {
zfslist=0;
}
{
suffix = "";
if ( NF > 1 )
{
n = split($0, a, " ", b);
/* Cheap check if it's a normal zfs list command */
if (a[0] == "NAME")
zfslist=1;
if (zfslist)
infix = " ";
else
infix = "";
/* number has to be 10 digits */
tmp = match(a[1], /.*home.*[0-9a-fA-F]+@([0-9]{10}($|\s))/, ary);
if (tmp)
{
dte = ary[1];
cmd = "date -d @" dte " +%Y%m%d_%H%M%S";
cmd | getline result;
a[1] = a[1] " - " result;
close(cmd);
}
else
{ /* see if I can find something that looks like a date */
tmp = match($0, /(^|\s)([0-9]{10})($|\s)/, ary);
if (tmp)
{
dte = ary[2];
cmd = "date -d @" dte " +%Y%m%d_%H%M%S";
cmd | getline result;
suffix = " - " result; /* print at the end because we don't know where it is */
close(cmd);
}
else
a[1] = a[1] infix;
}
line=b[0];
for ( i = 1 ; i <= n; i++)
line=(line a[i] b[i])
print line suffix;
}
else
print $0;
}
/* END { print "done"; } */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment