#!/usr/bin/perl

# Print matching fields from a file.  Fields don't have to line up in
# columns.  Each argument is a regexp to match a field, 'OR'ed together
#
# Changelog:
# 2017/12/20 V1.0  Tim Connors: Initial version
#
# Example usage: columngrep 'west-dvs1' '^........T......$' < /tmp/metrics.1min.log

use strict;
use warnings;

my @match = @ARGV;

foreach $_ (<STDIN>) {
  chomp $_;
  my @F = split(' ', $_);
  print join " ",
    map {
      my $match = 0;
      foreach my $test (@match) {
        if ($_ =~ /$test/) {
          $match=1;
          last;
        }
      }
      $match && $_ || ()
    } @F;
  print "\n";
}
