Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I run the below command for *.c,*.sh?

`find.exe . -name "*.h" -print0 | xargs -0 grep -i $folder`; `find.exe . -name "*.h,*.c,*.sh" -print0 | xargs -0 grep -i $folder`; +--->Will this work?

Replies are listed 'Best First'.
Re: Running find.exe for multiple extensions
by wind (Priest) on Apr 29, 2011 at 22:57 UTC

    I'd use File::Find

    use File::Find; use strict; use warnings; find(sub { print $File::Find::name if /\.(?:h|c|sh)$/; }, '.');

      Ya,I would also,but the thing is I need to grep for a variable,say $x in the resulting find.I am not able to combine both find and grep.Can you pls advise?

      These are my needs 1.Find all .h,.c,.sh and put in an array 2. Grep for $x for each array member(from above find list)and put in an array

        Any logic you can do in a shell, you can do using pure perl as well.

        I don't know what $x is, but there's no reason why you can't test against a mysterious $x variable as well.

        use File::Find; use strict; use warnings; my $x = shift; my @array; find(sub { push @array, $File::Find::name if /\.(?:h|c|sh)$/; }, '.'); my @x_files = grep {/\Q$x\E/} @array;