LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-07-2015, 10:35 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Rep: Reputation: 15
grep issue


I have a command

cat catalina.log | grep "CTC="

I want to list matches from last of the log files (i.e latest records first )

what changes do I require in my command ?
 
Old 07-07-2015, 11:14 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Use the tail command instead of cat. Tail reads the file from the end of the file in reverse order. You can also specify the number of lines for tail to read.

Code:
tail -n 20 catalina.log | grep "CTC="
See the tail man page for more information.
 
Old 07-07-2015, 11:51 AM   #3
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bigrigdriver View Post
Use the tail command instead of cat. Tail reads the file from the end of the file in reverse order. You can also specify the number of lines for tail to read.

Code:
tail -n 20 catalina.log | grep "CTC="
See the tail man page for more information.
This looks good.

If I want to see 5 lines above and below for each of these matches ...what will be command ?




Is it this ?

tail -n 20 catalina.log | grep "CTC=" -A 5 -B 5
 
Old 07-07-2015, 01:54 PM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by Volcano View Post
If I want to see 5 lines above and below for each of these matches ...what will be command ?




Is it this ?

tail -n 20 catalina.log | grep "CTC=" -A 5 -B 5
Well, almost. This should work:

Code:
tail -n 20 catalina.log | grep -C 5 "CTC="
The '-C' flag covers both before and after.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep issue nblarson Linux - Newbie 2 05-17-2012 09:03 AM
[SOLVED] ls grep issue Blizzard Linux - General 7 05-03-2012 03:38 AM
grep issue jack_9 Linux - Newbie 21 03-06-2012 06:02 AM
grep issue alape Linux - General 2 01-28-2012 11:49 AM
grep -v issue lleemon Linux - General 7 06-16-2003 03:50 PM

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

All times are GMT -5. The time now is 11:21 AM.

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