I have a Perl script that searches all files starting in the home directory for a string. i.e. file /usr/users/myhome/xzy contains the strings ‘theKing’ and ‘THEKING’.
The UNIX command:
find /usr/users/myhome -name '*' -exec grep -csi 'theking' -exec grep ls -l {} \;
Lists all files and indicates whether it found the string as follows:
/usr/users/myhome/notfound:0
…
/usr/users/myhome/xzy:2 where :2 says there are two matches
This script will NOT work on my LINUX box because of the above find command.
Can anyone help me with the correct find for LINUX RedHat 5.3.
Or does anyone know a better (especially faster) way to do this?
The UNIX command:
find /usr/users/myhome -name '*' -exec grep -csi 'theking' -exec grep ls -l {} \;
Lists all files and indicates whether it found the string as follows:
/usr/users/myhome/notfound:0
…
/usr/users/myhome/xzy:2 where :2 says there are two matches
This script will NOT work on my LINUX box because of the above find command.
Can anyone help me with the correct find for LINUX RedHat 5.3.
Or does anyone know a better (especially faster) way to do this?
Code:
#!/usr/bin/perl
system('clear');
$Target = 'theKing';
$Null = '/dev/null';
$Path = $ENV{HOME};
my $find = "find $Path -name '*' " .
"-exec grep -csi \'$Target\' " .
"-exec grep ls -l {} \\;" ;
$find = `$find`;
my ( @record ) = split("\n",$find);
foreach ( @record) {
next if ( /\.sh_history/ );
my ( $filename, $match ) = split(':',$_);
next if ( ! $match );
print "$_\n";
}