#!/usr/bin/perl -w # align -- align given substrings in standard input lines use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts('a', \%opt); sub VERSION_MESSAGE {} sub HELP_MESSAGE { print <) { chomp; push @lines, $_; } for $split (@splits) { $max = 0; # Find max column for split string for (@lines) { if (/(.+?)(\Q$split\E)(.*)/) { $max = length $1 if length $1 > $max; $_ = [$1, "$2$3"]; } } # Add one extra space before split $max++ if $opt{a}; # Add spaces before split for (@lines) { $_ = sprintf("%-${max}s%s", $_->[0], $_->[1]) if ref; } } print "$_\n" for @lines;