in reply to (How) can I use regex patterns to find matching lines in a textfile?

yet another way to do this.
script.pl maxnumofmatches word-to-find
#!/usr/bin/perl my $x=0;open(OF, ">OUT.txt");open(IF, "<IN.txt"); while(<IF>){if(/$ARGV[1]/){print OF "$_" if $x < $ARGV[0];$x++}} close IF;close OF;

Replies are listed 'Best First'.
Re: Re: (How) can I use regex patterns to find matching lines in a textfile?
by Ritter (Sexton) on Nov 20, 2002 at 12:32 UTC
    husoft, but "word-to-find" can't contain metacharacters like in the example I posted first, can it? Ritter
      You have to type only the word you want to find.
      If you want to be able to make it like the example you posted (with metachars).
      then replace /$ARGV[1]/ for eval($ARGV[1]).
        Just wonderful! thank you so much! and you too John your way works too!

        *so happy*!

        Ritter