in reply to isolating strings

If you have an input file named sql.txt with the following contents:

this is sql1 line1 this here is sql2 and now we have sql3 for a change

and if you use the following code:

#!/usr/bin/env perl use warnings; use strict; my $FileName = $ARGV[0]; my $String = $ARGV[1]; open(INFILE, $FileName) or die "Cant open the file\n"; # read in each line of the input file while (<INFILE>) { if (/$String/) { # If the $String is found... s/^.*$String//; # Delete $String and everything # before it. print; # then just print to STDOUT } }

then the following output will be produced if you execute this program with the arguments "sql.txt sql1":

line1

Is this what you are trying to accomplish? If not, then please provide some sample contents of your input file, and what your output should look like. Also, it is useful if you post the exact code which you have attempted; the code you provided does not compile.

Replies are listed 'Best First'.
Re^2: isolating strings
by clinton (Priest) on Jun 28, 2007 at 16:28 UTC
    Or to avoid matching twice:
    while (<INFILE>) { if (s/^.*$String//) { print; } }
Re^2: isolating strings
by dhudnall (Novice) on Jun 28, 2007 at 17:12 UTC
    Toolic: that was exactly what I was looking for. Thank you very much. Sorry if I wasn't very specific. The output is exactly how I wanted it and I just simply made it write to another file. Thanks