![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep and loop files | kashik | Shell Programming and Scripting | 4 | 06-16-2008 09:41 AM |
| Grep commands in loop | karthikn7974 | Shell Programming and Scripting | 0 | 04-28-2008 10:16 AM |
| grep and awk showing filename in loop | sjohns6 | Shell Programming and Scripting | 5 | 05-24-2007 09:59 AM |
| grep -v while loop | bobo | UNIX for Dummies Questions & Answers | 8 | 01-26-2007 10:53 PM |
| grep in a loop | gundu | Shell Programming and Scripting | 7 | 03-28-2005 05:59 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
Quote:
Code:
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. |
|
||||
|
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.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|