Skip to main content
added 9 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new({drawRowLine => 1});
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
    $t->setCols(@header);
    $rows = @ARGV / $cols;
    for ($i = 0; $i < $rows; $i++) {
      for ($j = 0; $j < $cols; $j++) {
        $cell[$i][$j] = $ARGV[$j * $rows + $i]
      }
    }
    $t->addRow(\@cell);
    print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new({drawRowLine => 1});
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
   $t->setCols(@header);
   $rows = @ARGV / $cols;
   for ($i = 0; $i < $rows; $i++) {
     for ($j = 0; $j < $cols; $j++) {
       $cell[$i][$j] = $ARGV[$j * $rows + $i]
     }
   }
   $t->addRow(\@cell);
   print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new({drawRowLine => 1});
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
    $t->setCols(@header);
    $rows = @ARGV / $cols;
    for ($i = 0; $i < $rows; $i++) {
      for ($j = 0; $j < $cols; $j++) {
        $cell[$i][$j] = $ARGV[$j * $rows + $i]
      }
    }
    $t->addRow(\@cell);
    print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
added 174 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new({drawRowLine => 1});
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
   $t->setCols(@header);
   $rows = @ARGV / $cols;
   for ($i = 0; $i < $rows; $i++) {
     for ($j = 0; $j < $cols; $j++) {
       $cell[$i][$j] = $ARGV[$j * $rows + $i]
     }
   }
   $t->addRow(\@cell);
   print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
.---------------------------------------------------------------------.
| Domain            | Without WWW    | With WWW                       |
+-------------------+----------------+--------------------------------+
| google.com        | 216.58.208.142 |                 74.125.206.147 |
|                   |                |                 74.125.206.104 |
|                   |                |                 74.125.206.106 |
|                   |                |                 74.125.206.105 |
|                   |                |                 74.125.206.103 |
|                   |                |                  74.125.206.99 |
+-------------------+----------------+--------------------------------+
| stackexchange.com |  151.101.65.69 | stackexchange.com.             |
|                   |   151.101.1.69 |                   151.101.1.69 |
|                   | 151.101.193.69 |                 151.101.193.69 |
|                   | 151.101.129.69 |                 151.101.129.69 |
|                   |                |                  151.101.65.69 |
+-------------------+----------------+--------------------------------+
| linux.com         |  151.101.193.5 | n.ssl.fastly.net.              |
|                   |   151.101.65.5 | prod.n.ssl.us-eu.fastlylb.net. |
|                   |    151.101.1.5 |                   151.101.61.5 |
|                   |  151.101.129.5 |                                |
'-------------------+----------------+--------------------------------'
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new();
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
   $t->setCols(@header);
   $rows = @ARGV / $cols;
   for ($i = 0; $i < $rows; $i++) {
     for ($j = 0; $j < $cols; $j++) {
       $cell[$i][$j] = $ARGV[$j * $rows + $i]
     }
   }
   $t->addRow(\@cell);
   print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
.---------------------------------------------------------------------.
| Domain            | Without WWW    | With WWW                       |
+-------------------+----------------+--------------------------------+
| google.com        | 216.58.208.142 |                 74.125.206.147 |
|                   |                |                 74.125.206.104 |
|                   |                |                 74.125.206.106 |
|                   |                |                 74.125.206.105 |
|                   |                |                 74.125.206.103 |
|                   |                |                  74.125.206.99 |
| stackexchange.com |  151.101.65.69 | stackexchange.com.             |
|                   |   151.101.1.69 |                   151.101.1.69 |
|                   | 151.101.193.69 |                 151.101.193.69 |
|                   | 151.101.129.69 |                 151.101.129.69 |
|                   |                |                  151.101.65.69 |
| linux.com         |  151.101.193.5 | n.ssl.fastly.net.              |
|                   |   151.101.65.5 | prod.n.ssl.us-eu.fastlylb.net. |
|                   |    151.101.1.5 |                   151.101.61.5 |
|                   |  151.101.129.5 |                                |
'-------------------+----------------+--------------------------------'
print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new({drawRowLine => 1});
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
   $t->setCols(@header);
   $rows = @ARGV / $cols;
   for ($i = 0; $i < $rows; $i++) {
     for ($j = 0; $j < $cols; $j++) {
       $cell[$i][$j] = $ARGV[$j * $rows + $i]
     }
   }
   $t->addRow(\@cell);
   print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"
.---------------------------------------------------------------------.
| Domain            | Without WWW    | With WWW                       |
+-------------------+----------------+--------------------------------+
| google.com        | 216.58.208.142 |                 74.125.206.147 |
|                   |                |                 74.125.206.104 |
|                   |                |                 74.125.206.106 |
|                   |                |                 74.125.206.105 |
|                   |                |                 74.125.206.103 |
|                   |                |                  74.125.206.99 |
+-------------------+----------------+--------------------------------+
| stackexchange.com |  151.101.65.69 | stackexchange.com.             |
|                   |   151.101.1.69 |                   151.101.1.69 |
|                   | 151.101.193.69 |                 151.101.193.69 |
|                   | 151.101.129.69 |                 151.101.129.69 |
|                   |                |                  151.101.65.69 |
+-------------------+----------------+--------------------------------+
| linux.com         |  151.101.193.5 | n.ssl.fastly.net.              |
|                   |   151.101.65.5 | prod.n.ssl.us-eu.fastlylb.net. |
|                   |    151.101.1.5 |                   151.101.61.5 |
|                   |  151.101.129.5 |                                |
'-------------------+----------------+--------------------------------'
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

Using perl's Text::ASCIITable module (also supports multi-line cells):

print_table() {
  perl -MText::ASCIITable -e '
    $t = Text::ASCIITable->new();
    while (defined($c = shift @ARGV) and $c ne "--") {
      push @header, $c;
      $cols++
    }
   $t->setCols(@header);
   $rows = @ARGV / $cols;
   for ($i = 0; $i < $rows; $i++) {
     for ($j = 0; $j < $cols; $j++) {
       $cell[$i][$j] = $ARGV[$j * $rows + $i]
     }
   }
   $t->addRow(\@cell);
   print $t' -- "$@"
}

print_table Domain 'Without WWW'    'With WWW' -- \
            "$@"   "${WOUT_WWW[@]}" "${WITH_WWW[@]}"

Where the WOUT_WWW and WITH_WWW arrays have been constructed as:

for domain do
  WOUT_WWW+=("$(dig +short "$domain")")
  WITH_WWW+=("$(dig +short "www.$domain")")
done

Which gives:

.---------------------------------------------------------------------.
| Domain            | Without WWW    | With WWW                       |
+-------------------+----------------+--------------------------------+
| google.com        | 216.58.208.142 |                 74.125.206.147 |
|                   |                |                 74.125.206.104 |
|                   |                |                 74.125.206.106 |
|                   |                |                 74.125.206.105 |
|                   |                |                 74.125.206.103 |
|                   |                |                  74.125.206.99 |
| stackexchange.com |  151.101.65.69 | stackexchange.com.             |
|                   |   151.101.1.69 |                   151.101.1.69 |
|                   | 151.101.193.69 |                 151.101.193.69 |
|                   | 151.101.129.69 |                 151.101.129.69 |
|                   |                |                  151.101.65.69 |
| linux.com         |  151.101.193.5 | n.ssl.fastly.net.              |
|                   |   151.101.65.5 | prod.n.ssl.us-eu.fastlylb.net. |
|                   |    151.101.1.5 |                   151.101.61.5 |
|                   |  151.101.129.5 |                                |
'-------------------+----------------+--------------------------------'