Grep Different Files Using a Loop?

I have a script to GREP for a text expression within certain files, the files being named file.11012008 thru file.11302008. 30 files in all, one for each day of the month.

Instead of entering the following 3 lines of code 30 different times, I'm trying to find a way to loop the process:

#insert the heading of the search
echo 11/01/2008 >> LOG_FILE

#insert blank line below the heading
echo "" >> LOG_FILE

#grep for the text and its entire line, then insert in log file.
grep "search_text" search/path/file.11012008 >> LOG_FILE

Thanks a million!

grep "search_text"  search/path/file.11*2008 > outputfile

Does this do what you want?

Try:

command:

for file in file11[0-3][0-9]2008 
do 
    printf "%s\n\n" $(sed s'#.*11\(..\)2008#11/\1/2008#' <<< $file) >> logfile
    grep "search_text" search/path/${file} >> LOG_FILE 
done

HTH Chris

Jim, the command does output all the search strings from the differents files to the logfile, but i'd still have to format the logfile so that each search string has a header. I need to make the other two lines of code do that for each string.

Chris, this outputs the search string of each file all into the logfile also, but it's not inserting the header or the blank line in the logfile (to separate the data according to the file they came from). Below is your code modified to the actual search criteria. Sorry about the change in path and file name values:

for file in event_demon.PRD.11[0-3][0-9]2008
do
    printf "%s\n\n" $(sed s'#.*11\(..\)2008#11/\1/2008#' << $file) >> logfile
        grep "sa_ZALE_REFMT_8" /autos/autotree/autouser/out/${file} >> LOG_FILE
        done

I now just need to figure how to work in the 2 "echo" code lines from my first post.

Yes, there is a little typo.
The headers go to: logfile
The search string to LOG_FILE

printf "%s\n\n" ... means print the string followed by two
linefeeds, so it takes care of your two echo commands in
one command. The string to print is the via sed adjusted
filename.

hi, something likes below, you may amend it to address your question

for i in file.*
do
	echo $i >> out.log
	echo >> out.log
	grep LEO $i >> out.log
	echo "------$i-----" >> out.log
done