You are not logged in.

#1 2005-10-25 10:42:12

Benedict_White
Member
From: Sussex, UK
Registered: 2004-05-27
Posts: 331
Website

Using OR in grep.

Hi.

i am having some trouble locating a way to do what I want.

I want to tail and follow a log file, which is easy, just tail -f /somelogfile.

Then rather than see the whole lot I want to pick bits out, for example if it was a BB2 and I want to just see posts I could do:

tail -f /some-log-file | grep some-entry

would produce what I want. However, what I want to see is lines that contain either some-entry, or some-other-entry or another-entry

So that I can pick out several types of interesting traffic with out having to have dozens of screens open.

Any one help? The man file implies I can do:

tail -f /some-log-file | grep some-entry |; some-other-entry |; a-third-entry

but this falls down with this bash error:
-bash: syntax error near unexpected token `;'


Kind regards

Benedict White

Offline

#2 2005-10-25 11:06:08

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: Using OR in grep.

If you use "|" don't use ";". But that's the other thing. For grep you can use something like this:

tail -F /some/path/some_file | grep "first-entry|second-entry|some other entry"

Offline

#3 2005-10-25 11:15:51

Benedict_White
Member
From: Sussex, UK
Registered: 2004-05-27
Posts: 331
Website

Re: Using OR in grep.

Yep, that works.

many thanks. I do like the power of the CLI, and the tools available to manipulate large files for interesting things without having to read the lot.

Many thanks for that. big_smile


Kind regards

Benedict White

Offline

#4 2005-10-25 11:20:00

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Using OR in grep.

grep [first-entry,second-entry,some other entry]
should work, the "," are like or's inside "[" brackets.

Offline

#5 2005-10-25 14:27:19

Benedict_White
Member
From: Sussex, UK
Registered: 2004-05-27
Posts: 331
Website

Re: Using OR in grep.

For some reason that seems to confuse grep and I get the whole tail.

I also tried with
tail -f /some-log-file | grep ['first-entry','second-entry','some other entry']

and that produced the same result.


Kind regards

Benedict White

Offline

#6 2005-10-25 14:47:09

Benedict_White
Member
From: Sussex, UK
Registered: 2004-05-27
Posts: 331
Website

Re: Using OR in grep.

lanrat's option seems to work well, but what I would like to do now is to pipe the output to another logfile so I tried something like this:

tail -f /some_log_file | grep "first_expression|second_expression|third_expression" > /some_other_logfile

but tailing that shows nothing at all.

Any thoughts?


Kind regards

Benedict White

Offline

#7 2005-10-25 23:49:31

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Using OR in grep.

tail -f /some_log_file | grep -e "first_expression|second_expression|third_expression" > /some_other_logfile 

"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB