grep multipule files output when file changes

I am using the following command to grep multipule files in the current directory.  I wanted to output to the screen what file grep is currently searching.  Would this need to be scripted or can this be done with a single command line?  If scripted could you provide an example, thank you.

OS: Ubuntu
grep ver: GNU grep 2.5.3

grep -a "blablabla" ./*.log
LVL 1
aehare70Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

farzanjCommented:
Use this script
SEARCH="blablah"
for file in $(ls)
do
echo "Now looking in $file"
egrep -i $SEARCH $file
done

Open in new window

0
savoneCommented:
in one line:

for i in `ls`; do echo "Now looking in $i"; grep -a "blablabla" $i; done

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
farzanjCommented:
Ok, try this one to include the hidden files as well.
SEARCH="blablah"
for file in $(ls -a)
do
if [[ -f $file ]]
then
echo "Now looking in $file"
egrep -ia $SEARCH $file
fi
done

Open in new window

0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

TintinCommented:
Do you really want/need to use the -a option with grep?

Anyway, here's a scripted version to do what you need.

#!/bin/bash
for file in (find . -type f -name "*.log" -maxdepth 1)
do
  echo "Checking $file"
  grep -a "blablah' $file
done

Open in new window

0
woolmilkporcCommented:
awk '{if($0~"blablabla") print FILENAME ":" $0; else print FILENAME}' ./*.log

wmp
0
woolmilkporcCommented:
OK, joke aside!

Try this:

awk '{if($0~"blablabla") print FILENAME ":" $0; else if(FNR==1) print FILENAME}' ./*.log

wmp
0
aehare70Author Commented:
Thank you for the input guys, it's very much appreciated.  I will test and verify which one works best this coming week and Accept a Solution then.  :)  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.