So I have created this script with help from previous posts on Perl Monks. It successfully reads from large tab and comma delimited text docs and picks out the rows of data which I require and places them into new docs that are much smaller and more manageable in size.
However I am unable to create a version of it which carries it out in bulk. My command for running it is as follows:
perl midasproc2.pl midas_wxhrly_199901-199912.txt 19260 "1999-12-15 1 +1:00"
This means that the a different value must be manually entered each time in place of "19260". Is it possible to alter the script to allow me to enter numerous values in addition to 19260?
1999-01-01 00:00, EGPK, ICAO, METAR, 1, 1006, 1001, , , 120, 13, 00, , + , , , , , , , 1000, , 1, , 96, 6, , $ 1999-01-01 00:00, EGSS, ICAO, METAR, 1, 484, 1001, , , 130, 8, 00, , , + , , , , , , 1000, , 1, , 120, , , , $ 1999-01-01 01:00, 03002, WMO, SYNOP, 1, 12, 1011, 4, 6, 160, 20, , , , + , , , , , 20, 440, 1004.1, 7, , 24, $
Below is the script I pieced together: ------------------------------------------
#!/usr/bin/perl use strict; use warnings; my ($record, $date, $outfile, $station, $sstation, $linecnt, $pcntg, @ +values); print "Processing \"$ARGV[0]\"...\n"; $date = $ARGV[2]; $station = $ARGV[1]; $outfile = $date.".txt"; $outfile =~ s/ /-/; print "For Date: $date and Station: $station\n\n"; $linecnt = `wc -l < $ARGV[0]`; open (INFILE, $ARGV[0]); open (OUTFILE, ">>", $outfile); while (<INFILE>) { $pcntg = int (($. / $linecnt ) * 100) ; print "$pcntg %\r"; chomp(); $record = $_; @values = split (',',$record); $sstation = $values[5]; $sstation =~ s/ //g; if ($values[0] eq $date && $sstation eq $station ) { print OUTFILE $record."\n"; # print "xx".$values[5]."xx\n"; print "Record written to $outfile...\n"; last; } } print "\nFinished\n"; close (INFILE); close (OUTFILE);
-----------------------------------------------
Any help anyone can offer will be greatly appreciated. Also I hope this code can help others filter through large delimited documents.
In reply to Bulk Reading and Writing of Large Text Files by Sterling_Malory
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |