LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 10-05-2006, 11:59 AM   #1
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 198

Rep: Reputation: 30
pulling info from files


I have a file that log certain events. I'd like to extract certain chunks of the file and redirect into a report. This command --
cat log.file|grep 'error'>report.error.log
-- only pulls that exact line containing the error. But the preceeding and proceeding few lines are also important. Is there a way to
1)search the log for a certain string
2)print the preceeding 5 and proceeding 5 lines
3)similarly to the above, redirect output into a file
?
Ideas?
 
Old 10-05-2006, 12:21 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
'man grep' says:

Code:
       -A NUM, --after-context=NUM
              Print NUM  lines  of  trailing  context  after  matching  lines.
              Places  a  line  containing  --  between  contiguous  groups  of
              matches.

       -B NUM, --before-context=NUM
              Print  NUM  lines  of  leading  context  before  matching lines.
              Places  a  line  containing  --  between  contiguous  groups  of
              matches.
 
Old 10-05-2006, 12:43 PM   #3
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 198

Original Poster
Rep: Reputation: 30
you're awesome. 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printing info files ttilt Linux - Software 1 01-09-2012 04:43 PM
need info on Linux caching of files jrfk2 SUSE / openSUSE 1 05-11-2006 05:18 PM
.ko files and X modules - info please sharkzf6 Debian 1 02-24-2005 06:48 PM
.ko files and X modules - info please sharkzf6 Linux - Newbie 0 02-18-2005 11:33 AM
Gentoo 2004.2 chroot/pulling files ghazz Linux - Distributions 2 01-25-2005 05:10 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 06:12 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