Correct syntax

Hi,

I want to check if file(s) exist even in subdirectories and perform an action. After searching here couldn't find solution that would work, but made my own solution that works fine:

if [ -f `find . | grep MLOG -m 1` ]
then
echo [MLOG]
egrep "$1|$2|$3" `find| grep MLOG`
else
echo "MLOG does not exist"
fi

That will check if 1 or more files named *MLOG* exist and executes egrep command with parameters supplied to the script.

How should that be with correct syntax? :slight_smile:

There is as well one bug I'd like to avoid, when it finds too many files then grep will fail because of too many arguments.

Thanks

Why don't you just execute the find command?

find . -name '*MLOG*' -exec grep -E "$1|$2|$3" {} +