#!/usr/local/bin/perl5
#I'll call this snippet exfields.pl as in "EXtractFIELDS"
#zcat command for gzipped files
$gzcatcmd="gunzip -c"; # I'll need this eventually
# Input parameters
$RegExp = ""; # Default no regexp
$MatchFld = ""; # Default no field match
$LastHdr = ""; # Last read header line
$DbFSplit = ' '; # Need this form for split
$DbOFSep = ' '; # Default output field delimiter
$VBarDel = 0; # Flag default not splitting by vertical bar
($progname = $0) =~ s/^.*\/([^\/*]+)$/$1/; # name of this program
while (@ARGV) {
$Param = shift @ARGV;
if ($Param eq "-s") {
$RegExp = shift @ARGV; # Search expression
} elsif ($Param eq "-f") {
$MatchFld = shift @ARGV; # Search field specifier
} elsif ($Param eq "-e") {
$FList = shift @ARGV; # field extract list
} elsif ($Param =~ /^\-/) {
&ErrorExit; #I'll define this later; you get the point
} else {
push @FileList,$Param;
}
}
# Flag to substitute for whitespace if the new field delimiter
#includes whitespace and the old one did not. The assumption is
#that if the old delimiter included whitespace, we do not need
#to convert existing whitespace in fields. May be modified by
# #DFD declaration..
if (($DbOFSep =~ /^ +$/) &&
($DbFSplit !~ /^ +$/)){
$FixSpaces = 'Y'; # can't have Null fields or whitespace
} else {
$FixSpaces = ''; # can't have Null fields or whitespace
}
@OrigFields = split(',',$FList);
unless (@FileList) {push @FileList,"-";}
print " @FileList\n";
####
exfields.pl -e Name,Rank,SerialNumber file.gz
####
Name,Rank,SerialNumber
####
####
####
exfields.pl -e Name,Rank,SerialNumber file.gz | Who,What,Where anotherfile.gz
####
print "@FileList_1\n"; #prints "Name" "Rank" SerialNumber"
print "@FileList_2\n"; #prints "Who" "What" "Where"