in reply to Re^4: copy line with character
in thread copy line with character

Hi Bill, thank you... I was able to get my answer from Stevieb. But I do have another question if you don't mind. for my $find, I want the lines beginning with A or C.

input sample: A123 A321 B123 B456 C321 C123 C654 output sample: A123 A321 C321 C123 C654

Im sure my code is wrong below but that is what I am trying to accomplish, locating the lines beginning with A or C

use strict; my $find = '^A' OR '^C'; open (NEW, ">", "output.txt" ) or die "could not open:$!"; open (FILE, "<", "Report.txt") or die "could not open:$!"; while (<FILE>) { print NEW if (/$find/); } close (FILE); close (NEW);

Replies are listed 'Best First'.
Re^6: copy line with character
by AnomalousMonk (Archbishop) on Nov 23, 2015 at 23:07 UTC
Re^6: copy line with character
by stevieb (Canon) on Nov 23, 2015 at 21:01 UTC
    Untested: my $find = qr/^(?:A|C)/;
Re^6: copy line with character
by BillKSmith (Monsignor) on Nov 24, 2015 at 15:41 UTC
    Sorry for my late reply. Others have already answered you latest question (use the syntax for a regular expression). You seem to have misunderstood my previous post. Stevieb's solution is correct and will work for almost any imaginable input. A much simpler solution may be possible depending on the format of the data file.
    Bill