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.


In reply to Re: isolating strings by toolic
in thread isolating strings by dhudnall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.