in reply to Search through multiple files and output results to new file

Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple instances of it or use the full potential.
I don't much about Windows, but I'm baffled by this statement. Why can't you run multiple instances of it?
Therefore I am trying to create a Perl script using Perl x64 can do the following grep:
grep -h %search_string% *.txt > retuned_Results.sl
Uhm, that's just one instance. Which, AFAIK, on Unix, doesn't use multiple cores either. And why doesn't it do what you want under Windows?

Of course, the Perl equivalent of the above is:

perl -ne 'print if /%search_string%/' *.txt > retuned_Results.sl
but if the grep doesn't do what you want, I fear the above doesn't do what you want either.

Replies are listed 'Best First'.
Re^2: Search through multiple files and output results to new file
by BrowserUk (Patriarch) on Aug 24, 2010 at 16:25 UTC
    Why can't you run multiple instances of it?

    Two reasons:

    1. Each instance would be trying to process the same files.

      Which would mean lots of "file in use" errors and/or duplicated results.

    2. The multiple instances would be trying to redirect their output to the same file.

      Even if you use append (>>), Windows won't let you do that. Not sure if *nix will?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Each instance would be trying to process the same files.
      Oh. I never got the impression that the OP wanted this. I fail to see why that's a benefit.
      Which would mean lots of "file in use" errors and/or duplicated results.
      Windows doesn't allow two processes to open the same file? That sounds like an easy DoS.
      The multiple instances would be trying to redirect their output to the same file. Even if you use append (>>), Windows won't let you do that. Not sure if *nix will?
      Unix allows multiple processes to write to the same file. And if the file is opened in append mode, all write()s will go to the end of the file.
        Oh. I never got the impression that the OP wanted this. I fail to see why that's a benefit.

        If you start two concurrent instances of grep with a wildcard filespec, (win or *nix), then both instances will expand that wildcard to the same list.

        So then the problem becomes, how do you distribute the file list across multiple grep instances?

        Windows doesn't allow two processes to open the same file?

        It does, but not by default. And the permissions required are not available from perl.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.