Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: pattern search in all the files in a directory

by 2teez (Priest)
on Feb 19, 2013 at 06:41 UTC ( #1019460=note: print w/ replies, xml ) Need Help??


in reply to pattern search in all the files in a directory

hi Bharath666,
Please, could you show what you have done using Perl, where and how you having troubles making it work.
Or check How do I post a question effectively?

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: pattern search in all the files in a directory
Re^2: pattern search in all the files in a directory
by Bharath666 (Novice) on Feb 19, 2013 at 07:13 UTC

    Actually I am not able to take an exact move at this point. I thought of using find(subroutine,directory_path) and inside the sub-routine I want to traverse through the entire directory for all its entries. For every entry I want to put a check whether it is a readable file or not. If the file is readable, I want to search for the required pattern "keyword : Multinode" in the file found. If we hit with a success, the entire find command should result in a non-empty string(preferably only the existing directory Name) otherwise with an empty string. Please let me know if you need any further information

      Actually I am not able to take an exact move at this point Why is that?
      I thought of using find(subroutine,directory_path) That is a way to go. Try it out.
      If you could describe what you want like you did above, it shows you could make it happen. Try it out and you would be glad you did.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

        I tried like the below and I got the solution that I desired. Can you please tell me if it can be further optimized or is enough to get proceed further? Thanks

        find(\&do_process, "$dirname" ); sub do_process { chomp($_); if (-r "$_"){ $file_name = $_; open (my $fh,"< $file_name"); while(<$fh>) { chomp(); if (/\bkeyword : Multinode\b/i) { $KeyMnode = "$file_name:$_"; } if (/\bkeyword : Threads\b/i) { $KeyThreads = "$file_name:$_"; } } } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-04-20 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls