#!/usr/local/bin/perl -w # getting the source code from the file ##################################################################### open(IN,"/home/uila3/rhuff/doh/090809.txt") or die "cannot open file1 for reading\n"; open(OUT,">/home/uila3/rhuff/doh/test.txt") or die "cannot open file2 for writing\n"; my $start = 0; my $count=0; while() { chomp; $count++; next if( /^\s*$/ ); #skip empty lines if( /^END_DATA\s*$/ ) #end if this word found { $start = 0; next; } if( /VARIABLE,\s*(.*)$/ ) { my ($sec,$min,$hour,$day,$month,$yr19,@rest) = localtime(time); print OUT $_ ; next; } if( ($start==0) && ( /^BEGIN_DATA\s*$/ ) ) #starts with this word only { $start = 1; next; } print OUT $1," ",$2,"\n" if( (($start==1)) && ( /^([^,]*),.*,\s*([0-9.-]*)$/ ) ); } close(OUT); close(IN); print "No. of lines parsed $count"; #### # getting the source code from the file my $target_data; { local $/ = "VARIABLE,PM2.5\n"; open my $INFILE, '<', '/home/uila3/rhuff/doh/2010090913.txt' or die "Couldn't open /home/uila3/rhuff/doh/2010090913.txt: $!"; my $discard = <$INFILE>; $target_data = <$INFILE>; close $INFILE; } print $target_data; print '*' x 20; for my $line (split /\n/, $target_data) { if ($line =~ m{ \A ( \p{Uppercase}{2} \d+ ) , .* , (\d+) }xms ) { print "$1 $2"; } }