[KLUG Members] Parsing a large file
Dirk H Bartley
members@kalamazoolinux.org
06 Feb 2004 15:47:26 -0500
On Fri, 2004-02-06 at 15:38, Dirk H Bartley wrote:
>
> #!/usr/bin/perl
> $, = ' '; # set output field separator for print this is a tab here
> $\ = "\n"; # set output record separator for print
> open( INFILE, "/home/user/inputfile" );
> open( OUTFILE, "/home/user/outputfile" );
>
> while (<INFILE>) {
> # split with a : as the delimiter or choose your own regex
> @Fld = split(":", $_, 99999);
> chomp $_; # remove any cr and lf
> # $_ is each line one by one
> #perform any sed type regex subs
> $Fld[2] =~ s/abc/xyz/g;
> # output in any order desired with the delimiter set above in $, $\
> print $Fld[23],$Fld[2],$Fld[17];
> }
Bad Dirk, Replying to his own, but I have a correction
print OUTFILE $Fld[23],$Fld[2],$Fld[17];
The original would print to standard out. All apologies for my
blasphemous behavior.
Dirk