cliffordw |
05-24-2012 12:17 AM |
Quote:
Originally Posted by TobiSGD
(Post 4685625)
I would do it this way (small script, not tested, currently no Linux available):
Code:
#!/bin/zsh
# The script has to be started with $1 = path to search in, $2 = first match, $3 = second match
# No exception handling, if you want it add it.
#
# First find all files that contain that first match
FIRST=$(grep -rl $2 $1/*)
# Now search for the second match in those files
for i in $FIRST
do
if [ grep -v $3 $i ]
then
echo $i
fi
done
|
My I suggest a few minor changes to the above script, namely:
* Change the shell for AIX (as per OP)
* Replace the filename wildcard to avoid "parameter list too long" errors
* Quote arguments and file names to handle spaces in either
* The "-v" in the second "grep" command doesn't look right - that would find lines NOT containing the pattern?
The modified script would look like this:
Code:
#!/usr/bin/ksh
# The script has to be started with $1 = path to search in, $2 = first match, $3 = second match
# No exception handling, if you want it add it.
#
# First find all files that contain that first match
find "$1" -type f -print | xargs grep "$2" | while read i
do
# Now search for the second match in those files
if [ grep "$3" "$i" > /dev/null ]
then
echo "$i"
fi
done
Hope this helps :-)
|