cbolden has asked for the wisdom of the Perl Monks concerning the following question:

I've created a regex to filter files of type (.php) from a directory while parsing the file to find an area number which is a six digit integer with no delimiter. I also want to save the results in a .txt file. The following script doesn't provide the desired result. Any assistance, much appreciated.

egrep -r '\<[0-9]{6}\>' /home/cvsuser/cvsroot/ot/ | grep \.php > otRes +ults

Replies are listed 'Best First'.
Re: Regular Expression
by ww (Archbishop) on Oct 28, 2014 at 16:07 UTC

    If the question you intended -- but didn't ask -- is "Can I do this in Perl?" the answer is an emphatic "YES!"
    Using Perl, you can do almost anything except put the toothpaste back in the tube or wash the windows.

    But, in accord with the local customs, values and mores, you really should:

    1. Ask a Perl question.... not a *nix-ish one
          and
    2. Show your code; quote any errors or warnings; and describe how your attempt at that point fails or fails to accomplish what you want.

    If you undertake that (using perldoc -f open, perldoc perlre or, perhaps, the Tutorials at this site) you'll find welcome and high quality help.


    ++$anecdote ne $data


Re: Regular Expression
by Anonymous Monk on Oct 28, 2014 at 21:46 UTC
    Welcome to the Monastery,

    Follow the advice suggested by WW and show us some example of how your file names look like. Perl is excellent in regular expression and therefore I guess your question is relevant to this forum although the solution you opted for is not relevant to the scope of Perl.

    Untested code but perhaps you can expand from there:

    ls /home/cvsuser/cvsroot/ot/ | perl -lane 'if(/[0-9]{6}/){print}'