for file in `ls *.txt`
do
echo "********check on $file********"
if grep WINDOWS $file ; then
if grep UNIX $file; then
if grep ORACLE $file; then
echo "$file is the file which I am looking for. "
fi
fi
fi
done
Utility glark allows you to make a single pass through a file noting when a complex combination of matching expressions is satisfied:
#!/usr/bin/env bash
# @(#) s1 Demonstrate complex matching expressions, glark.
# http://www.incava.org/projects/glark/
# Infrastructure details, environment, commands for forum posts.
echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
c=$( ps | grep $$ | awk '{print $NF}' )
version >/dev/null 2>&1 && s=$(_eat $0 $1)
[ "$c" = "$s" ] && p="$s" || p="$c"
version >/dev/null 2>&1 && version "=o" $p my-nl glark
set -o nounset
echo
FILES="data*"
echo " Content of files :" $FILES
my-nl $FILES
echo
echo " Results with utility glark:"
glark -l \( \( ORACLE -a -1 UNIX \) -a -1 WINDOWS \) $FILES
exit 0
producing (on your files named data1 and data2):
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
GNU bash 3.2.39
my-nl (local) 296
glark, version 1.8.0
Content of files : data1 data2
==> data1 <==
1 UNIX
2 ......
3 WINDOWS
4 ........
5 ORACLE
==> data2 <==
1 UNIX
2 .......
3 WINDOWS
Results with utility glark:
data1
The somewhat easiler-to-understand expression:
glark -l \( ORACLE -a -1 UNIX -a -1 WINDOWS \) $FILES
also seems to work.
The utility was in the Debian repositories for me. See the URL in the script if you need to download it yourself, and for additional information, such as examples of use. The code is actually written in ruby, so one would need that as well.