# /usr/bin/perl -Tw #----------------------------------------------------------------------- # Name: trimslurp.pl # Description: turn multi-line records into single-line records # Author: Chuck Colht, Internet Alaska # Creation Date: <2002 #----------------------------------------------------------------------- # # Takes a file piped in and looks for lines that start on left margin. # It combines that line with all subsequent lines that do not start on # the left margin and concatenates them into a single tab delimited # line. This allows you to grep on the entire structure and return the # structure instead of just the line you're looking for. # #----------------------------------------------------------------------- use strict; # log script usage my $recordline; my $record = ''; my $debug = 0; $|++; # Set buffer autoflush for default filehandle #----------------------------------------------------------------------- sub trim { $_[0] =~ s/^\s*//; # trim leading spaces $_[0] =~ s/\s*$//; # trim trailing spaces return $_[0]; } #----------------------------------------------------------------------- # main loop $ENV{PATH} = '/usr/bin:/usr/sbin'; while (<>) { next unless m/\S/; # skip it if it's empty chomp; $recordline = $_; if (/^\S/) { # if no leading spaces # print "non-space\n" if ($debug > 0); print $record . "\n"; # print this one $record = ''; # clear it to start over trim($recordline); $record .= ( $recordline); } else { # print "space" if ($debug > 0); $record .= "\t"; trim($recordline); $record .= ($recordline); } } print $record . "\n"; # print the last one, too #----------------------------------------------------------------------- __END__