![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to grep word from .gz files & .z files | udaya_subbu | Shell Programming and Scripting | 8 | 08-08-2008 02:53 AM |
| grep from .z files | koho | Shell Programming and Scripting | 4 | 11-15-2007 10:55 PM |
| listing files along with grep -v | charlie11k | UNIX for Dummies Questions & Answers | 5 | 06-01-2007 04:00 AM |
| modifying grep to get files only within last 2 hrs | ragha81 | Shell Programming and Scripting | 3 | 01-11-2007 04:11 PM |
| grep data from files | getdpg | Shell Programming and Scripting | 2 | 01-17-2006 09:57 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script to grep several files
Hi I am totally new to Unix and I am in need of a script that can grep several files at once.
the script needed: change directory grep for keywords "error" "fail" "warning" in different files with different names, same extention but specific file names. if any of the keywords is found to show the line number and the error I usually run this grep manually every hour and it's time consuming, running a cron is not an option, so I would just copy and paste the script when needed. Any help will be greatly appreciated. Thanks, Newby in need. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
use -n option for grep.
Code:
grep -en "error|fail" * |
|
#3
|
||||
|
||||
|
Hi Bhargav,
Is there any way to grep a keyword in all files - including those in the subdirectories as well. I usually use this method of coding: for j in `find ./*` do grep <keyword> $j done But just out of curiosity - is there any other methods to perform the same.. which looks much simpler (instead of taking such multiple lines!!) |
|
#4
|
||||
|
||||
|
Quote:
Cheers ZB |
|
#5
|
|||
|
|||
|
You can use find + xargs + grep to do this by one command as,
find <dir to be grepped> -name "*" | xargs grep -ne 'error|fail|warning' It will do it. |
|||
| Google The UNIX and Linux Forums |