grep question


 
Thread Tools Search this Thread
# 1  
grep question

I wanted to search a for all lines containing ERROR but not errors that contained the word "foo" (for example). The only way I could figure out to do it was:

grep ERROR myfile.log | grep -v foo

is there a way to do this with one grep command instead of two? One grep is faster than two, especially for large files like log files.Smilie
# 2  
Use:

Code:
awk '/ERROR/&&!/foo/' file

or:

Code:
fgrep ERROR file|fgrep -v foo

# 3  
Sanju

Hi use
grep -r "ERROR" *
# 4  
radoulov, isn't "fgrep ERROR file|fgrep -v foo "-the same as doing "grep ERROR file | grep -v foo", except it uses fgrep instead of grep? Is there some advantage for fgrep in this case?

The awk thing is pretty cool - I tried it and it works great. I'll have to look into awk more - I know nothing about it (yet!).

sanjustudy, I don't understand how grep -r "ERROR" * will do what I want. I thought "-r" was for searching directories recursively. Also, I don't see how it searches for "foo".
# 5  
Quote:
Originally Posted by tim-bobby
radoulov, isn't "fgrep ERROR file|fgrep -v foo "-the same as doing "grep ERROR file | grep -v foo", except it uses fgrep instead of grep? Is there some advantage for fgrep in this case?
[...]
If you don't search for a RE, it should be faster:

Quote:
DESCRIPTION
The fgrep (fast grep) utility searches files for a character
string and prints all lines that contain that string. fgrep
is different from grep(1) and egrep(1) because it searches
for a string, instead of searching for a pattern that
matches an expression. It uses a fast and compact algorithm.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #444
Difficulty: Easy
Scientific Linux is an Enterprise Linux rebuild sponsored by Fermi National Accelerator Laboratory.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question on grep

Hello all, I'm trying to grep the string "scott" from all files whose names are like srvr*.log and that were created "Nov 15"...I'm trying the following command but throws an error message...seems like the syntax is incorrect.. grep scott < ls -l srvr*.log|grep "Nov 15" Thanks for your... (9 Replies)
Discussion started by: luft
9 Replies

2. Shell Programming and Scripting

a question on grep

hi, I used grep "total packets" to filter a file and get the following results, what I want is to get the lines with only one "total packets", are there any methods? thanks! total packets: 131 total packets: 55 total packets: 76 total... (4 Replies)
Discussion started by: esolve
4 Replies

3. Shell Programming and Scripting

Question about grep

can anyone tell me what the \/$ means? from grep \/$ (8 Replies)
Discussion started by: Nick1097
8 Replies

4. Shell Programming and Scripting

Question in grep

I have a requirement where I need to search for 26 consecutive 000000.000 in a file. I tried using grep but it is not working. The string I need to search is ... (2 Replies)
Discussion started by: gpaulose
2 Replies

5. UNIX for Dummies Questions & Answers

Another grep question

Hi guys, I'm very new to unix but am liking it a lot so far, so please be gentle on this newb. I tried using the search for this question, but no luck. Anyways, i've got a few data fields... for example John Adress1 Adress2 Sam Adress3 Adress4 Jason Adress5 Adress6 Is... (4 Replies)
Discussion started by: Uss_Defiant
4 Replies

6. Shell Programming and Scripting

grep question

hello people, All my servers have 4 mounts with this norme. For example, if my hostname is siroe. df -h | grep `hostname` /dev/dsk/c1t3d0s6 404G 399G 800M 100% /siroe3 /dev/dsk/c1t2d0s6 404G 399G 800M 100% /siroe2 /dev/md/dsk/d6 20G 812M 19G ... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

7. UNIX for Dummies Questions & Answers

grep question

Hi, I have a log file that I'm trying to tidy up using grep. The log file contains a lot of lines like the ones below: 2> change archivelog all crosscheck; 3> release channel; 4> run 5> { 6> . . . 15> exit; Also it contains a lot of lines like these: RMAN-06157 : Message.... ... (2 Replies)
Discussion started by: mz043
2 Replies

8. Shell Programming and Scripting

Question on Grep!

Hi all, I am relatively new to Unix... Pls help me with the following : is there an option ion grep to find the first and last occurence of a pattern in a file? if not how else can this be accomplished? Cheers, Bourne. (5 Replies)
Discussion started by: bourne
5 Replies

9. UNIX for Dummies Questions & Answers

Grep question

sometimes I'll do a search with grep and it just goes down a line and hangs. What is it doing? (4 Replies)
Discussion started by: eloquent99
4 Replies

10. UNIX for Dummies Questions & Answers

grep question

what is the format for grep if I want to search from the current directory and through all its subdirectories?:) (3 Replies)
Discussion started by: pkappaz
3 Replies

Featured Tech Videos