LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-27-2008, 03:02 PM   #1
b3nder
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 0
grep command from bottom to top of a file.


Trying to figure something out that hopefully someone can shed some light on...

What I am trying to do is search a log file from the bottom to the up grabbing the last 10 instances on an ip (or string i specify)...

when using 'tail -xxxx /var/log/messages | grep x.x.x.x'.. this will only show results if it is in the range xxxx that I specify... which is Ok because i can keep increasing the xxxx range until i get enough results but that seems tedious and that there has to be an easier way to accomplish this..



anyone have any idea's? been searching Google for the past few hours and not finding anyway to work with grep to search from bottom up and stop when i get a certain number of hits.


Thanks!
 
Old 06-27-2008, 03:38 PM   #2
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
Use 'tac' (cat backwards )
Code:
 tac your.log | grep stuff
I didn't know about it but found it on perl monks. You learn something new everyday.
 
Old 06-27-2008, 03:59 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Just exchange the commands:
Code:
grep x.x.x.x /var/log/messages | tail -10
 
Old 06-30-2008, 08:08 AM   #4
b3nder
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks!

tac works perfect for the results that i want.

As for the "grep ' xxxx ' /var/log/messages | tail -10", it does return the correct results, the only problem that i found with using that is that it does end up having to search through the entire file and then it returns the last results.. takes a long time depending upon the size of the document.

appreciate the help as always!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Xubuntu top and bottom line disappeared wanjiwz Linux - Newbie 1 06-03-2008 12:26 PM
Suddenly - No panels, top or bottom Posterboy Fedora 5 06-02-2007 12:23 PM
command to read from bottom to top (like more) tommy916 Linux - Newbie 3 07-01-2005 07:34 PM
Getting multi-colour lines from top to bottom djeanveau Linux - Newbie 1 01-30-2005 12:02 PM
FC3: Top and Bottom panel Cyberian Fedora 1 11-09-2004 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration