LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-08-2010, 01:37 PM   #1
agangsto
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Rep: Reputation: 0
Need some help reading part of a log file


Hello.

I have a problem with reading a log file the way I want to.

I have many systems reporting errors to a file called "error.log" in a "main" system.
Only two of the systems in the file concerns me. (sys1 and sys2.)
To read the messages for the two systems I use the command:
Code:
tail -f error.log | egrep 'sys1'|'sys2'
This gives me only the information about sys1 and sys2.
However, this also gives me more information than I'd like.
Example of information given:
sys1 cooling warning
sys2 door open
sys2 cooling error
sys1 lost connection with hhut1
sys1 gained connection with hhut1
sys2 door closed

Lets say I want to exclude the information about cooling and door. My idea was to use this command:
Code:
tail -f error.log | egrep 'sys1|sys2' | egrep -v 'cooling|door'
My guess is that you know this does not work. I also guess that you know why.

Any one that care to help me out?
 
Old 07-08-2010, 01:44 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

What you posted should basically work fine:

1. You want to use "egrep" (for the "|" functionality)
2. You want all entries in the error log for "sys1" or "sys2"
3. You want to EXCLUDE any entries for "cooling" or "door"

Try this:
Code:
egrep 'sys1|sys2' error.log|egrep -v 'cooling|door'
Works for me
 
Old 07-08-2010, 01:47 PM   #3
agangsto
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Yes, what you said works fine, but if you look at my code I also have tail -f, and then it won't work.

Last edited by agangsto; 07-08-2010 at 01:49 PM.
 
Old 07-08-2010, 04:49 PM   #4
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
You can use sed:

Code:
tail -f error.log | sed -nr '/door|cooling/ d ; /sys1|sys2/ p'

Last edited by eSelix; 07-08-2010 at 04:55 PM.
 
Old 07-08-2010, 05:13 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You have to flush the output from grep to let it pass through the second pipe:
Code:
tail -f error.log | grep -E --line-buffered 'sys1|sys2' | grep -E -v 'cooling|door'
 
Old 07-09-2010, 02:14 AM   #6
agangsto
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
This works:
Code:
tail -f error.log | sed -nr '/door|cooling/ d ; /sys1|sys2/ p'
This does NOT work: (not for me anyway)
Code:
tail -f error.log | grep -E --line-buffered 'sys1|sys2' | grep -E -v 'cooling|door'

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Kernel Log: Coming in 2.6.34 (Part 2) - File Systems LXer Syndicated Linux News 0 04-23-2010 04:21 PM
PHP - reading a log file that could be written to. sanimfj Programming 1 12-18-2009 08:04 PM
LXer: Reading Packets with Libpcap Part 3 LXer Syndicated Linux News 0 01-03-2009 11:50 PM
webalizer reading wrong log file blizunt7 Linux - Software 0 05-27-2007 02:03 AM
Log file reading Garak Linux - General 5 07-08-2003 06:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration