Similar idea to anchal_khare . Search each file twice if necessary.
find /var/www/hrmtest/cache/upload/ -type f -name '*.doc' | while read filename
do
egrep -l --ignore-case "Master en Achats" "${filename}"; FOUND1=$?
# Leave the loop if we don't find the first string
if [ "${FOUND1}" -ne 0 ]
then
continue
fi
#
egrep -l --ignore-case "complet" "${filename}"; FOUND2=$?
# Leave the loop if we don't find the second string
if [ $FOUND2 -ne 0 ]
then
continue
fi
# Report matching file matching both conditions
echo "${filename}"
done
If these files are Microsoft Word format document the process is not reliable. The "egrep" program is only suitable for searching unix format ascii text files where each record are of a reasonable length and terminated with a line-feed character.
A Microsoft Word document is not like this. Even a "space" character can be a non-ascii character.
@felipe.vinturin
I'm afraid that your script contains the same mistake as several earlier attempts in this thread.
A "grep -l" outputs a filename. The second "grep -l" in your script will look for a filename containing the string "complet".
# cat 1.dat
hello
world
this
is
a
file
# cat 2.dat
this
is
hello
world
file
# cat 3.dat
hello
this
file
doesnt
have
those
two
words
The below program will print the file names only if they have both words "hello" and "world".
#! /usr/bin/perl -w
use strict;
my ($flag1, $flag2, @x);
@x = <*.dat>;
for (@x) {
$flag1 = 0;
$flag2 = 0;
open I, "< $_";
for (<I>) {
$flag1 = 1 if (/hello/);
$flag2 = 1 if (/world/);
}
print "$_ has hello and world\n" if ($flag1 == 1 && $flag2 == 1);
close I;
}
Output:
# ./hello_world.pl
1.dat has hello and world
2.dat has hello and world