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?
 
savoneCommented:
in one line:

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

0
 
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
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.