Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9306017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:04:35+00:00 2026-06-19T00:04:35+00:00

I have the pattern something like keyword : Multinode. Now, I need to search

  • 0

I have the pattern something like “keyword : Multinode”. Now, I need to search this pattern in all the files in a directory. If we found the pattern in any of the file, a non empty-string should be returned. It may contain file-name or directory name

In shell scripting the following will do the same

KeyMnode=grep -w "keyword : Multinode" ${dirname}/*

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.

I want this to be done using perl. Please help me with the solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T00:04:37+00:00Added an answer on June 19, 2026 at 12:04 am

    Here are some Perl tools that will be useful in doing what you described:

    • File::Find will do a recursive search for files in a directory and its children, running code (the \&wanted callback in the docs) against each one to determine whether it meets your criteria or not
    • The -r operator will tell you whether a file is readable (if (-r $file_name)...)
    • open will get you access to the file and <$fh> will read its contents so that you can check with a regular expression whether they match your target pattern
    • Adding \b to the beginning and end of the pattern will cause it to match only at word boundaries, similar to grep‘s -w switch

    If you have more specific issues, please post additional questions with code that demonstrates them, including statements both of what you expected to happen and of how the actual results differed from your expectation and we’ll be happy to help resolve those issues.

    Edit: Cleaned up and runnable version of code from comment:

    #!/usr/bin/env perl    
    
    use strict;
    use warnings;
    use 5.010;
    
    use File::Find;
    
    # Get $dirname from first command-line argument
    my $dirname = shift @ARGV;
    
    find(\&do_process, $dirname); # quotes around $dirname weren't needed
    
    my ($KeyMnode, $KeyThreads);
    
    sub do_process {
    #  chomp($_); - not needed; $_ isn't read from a file, so no newline on it
      if (-r $_) {  # quotes around $_ weren't needed
        # $_ is just the final part of the file name; it may be better for
        # reporting the location of matches to set $file_name to 
        # $File::Find::name instead
        my $file_name = $_;
        open(my $fh, '<', $file_name);  # Use three-arg open!
        while (<$fh>) {
          chomp();
          # Note that, if you store all matches into the same scalar values,
          # you'll end up with only the last value found for each pattern; you
          # may want to push the matches onto arrays instead.
          if (/\bkeyword : Multinode\b/i) { $KeyMnode   = "$file_name:$_"; }
          if (/\bkeyword : Threads\b/i)   { $KeyThreads = "$file_name:$_"; }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so if I have this pattern: ab&bc&cd&de&ef And I need to replace all
Intro: The basic Fragments Tutorial pattern goes something like this: On a tablet, have
Say you have a pattern like this: @[a-z]+\s[\d] is it useful to have something
Is there any possibility in the prefix-function of a given pattern to have something
I have a pattern like this that matches multiple sets of values: (((\w+) (\d+))+)
I have something like this AD ABCDEFG HIJKLMN AB HIJKLMN AC DJKEJKW SJKLAJL JSHELSJ
I have a file like this: 10 15 something I want to read this
What is the closest design pattern for something like an issue tracker? You have
I have a hierarchy that looks something like this: class Base { public: void
I have a pattern that looks like this: pattern = '.*class=(.*)' and it gives

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.