Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: One-liner for Matching a Regex in a Directory of Files

by allolex (Curate)
on Jan 10, 2004 at 20:56 UTC ( [id://320376]=note: print w/replies, xml ) Need Help??


in reply to One-liner for Matching a Regex in a Directory of Files

a four letter word starting with M

In that case, you should also be using the carat to tell your regex that the letter "M" is found just after the beginning of the filename.

m/^M[A-Z]{3}/

So you get:

perl -le'foreach ( <*.txt> ) { print if /^M[A-Z]{3}/ }'

--
Allolex

Replies are listed 'Best First'.
Re: (2) One-liner for Matching a Regex in a Directory of Files
by svsingh (Priest) on Jan 11, 2004 at 02:15 UTC
    Sorry, I didn't mean to imply that that M was at the beginning of the file. Each text file is a separate essay and the acronym was just a word in the body of the file.

    I combined ideas from both tips to come up with the following (semi-Perl) solution. Thanks for your help Paladin and allolex.

    for %a in (*.txt) do @perl -ne "if (m/ (M[A-Z]{3}) /) { print qq($1\n); }" %a

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://320376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found