CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Searching for files that contain a string

 



tbone587
User

Jun 17, 2011, 4:57 PM

Post #1 of 6 (1030 views)
Searching for files that contain a string Can't Post

Is there a way to search through a directory through all .cfg files to see if they contain a specific number? For instance if I wanted to find "tristan" in all .cfg files in the /home directory and all directories below.


miller
User

Jun 17, 2011, 5:06 PM

Post #2 of 6 (1029 views)
Re: [tbone587] Searching for files that contain a string [In reply to] Can't Post

Use File::Find

- Miller


FishMonger
Veteran / Moderator

Jun 17, 2011, 5:37 PM

Post #3 of 6 (1028 views)
Re: [tbone587] Searching for files that contain a string [In reply to] Can't Post

or File::Find::Rule http://search.cpan.org/~rclamp/File-Find-Rule-0.32/lib/File/Find/Rule.pm


tbone587
User

Jun 18, 2011, 7:56 PM

Post #4 of 6 (1014 views)
Re: [FishMonger] Searching for files that contain a string [In reply to] Can't Post

I messed around with this module and I can have it find files with specific names, but not files that contain information. If i want to display all .cfg that contain "tristan" what is the syntax? Also, I am trying to find files and then delete them. How do I store the output, then cycle through to unlink them?


miller
User

Jun 18, 2011, 9:03 PM

Post #5 of 6 (1013 views)
Re: [tbone587] Searching for files that contain a string [In reply to] Can't Post

It sounds like you just want to use a unix grep.

Nevertheless, if you want to do this in perl, just do the project step by step. Start off with setting up File::Find so that it will find all the files with .cfg. Then do read those files that satisfy the first condition to see if they contain the text that you want.

- Miller


tbone587
User

Jun 18, 2011, 9:11 PM

Post #6 of 6 (1010 views)
Re: [miller] Searching for files that contain a string [In reply to] Can't Post

well i am never using this module again. i accidentally deleted entire directory and sub directories. trying to unlink a specific file deleted everything. obviously i did something wrong, but still no warnings or anything.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives