I am looking for a way to read an input file and print only select lines to an output file in Perl. The lines I want to print to the output file all begin with xxxx.xxxx.xxxx, where x is an alphanumeric character (the periods are periods, not wildcards). The lines do not all have the same ending, if that makes a difference. I’m thinking something like the following (the condition of the if statement is all that is really missing as far as I can tell).
open(IN, "<$csvfile");
my @LINES = <IN>;
close(IN);
open(OUT, ">$csvnewfile");
print OUT @LINES if ([line starts with xxxx.xxxx.xxxx]);
close(OUT);
Thanks in advance!
Here is a better way to loop through your lines. It avoids loading your whole input file into memory at once:
Keep in mind that the
\wcharacter class also includes underscores. To avoid underscores: