• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 719
  • Last Modified:

to grep log files

Hi, I am using egrep to grep for a particlular date in a log file. However I am getting only first line.

Example in the log below, When I egrep for Nov 12, 2008 I am getting only the first line, but I require all the lines following that. Is there any way by which we can do that.

<Nov 12, 2008 11:03:06 PM EST> <Error> <HTTP> <BEA-101214> <Included resource or file "/motoconfig/gomez_bd_header.html" not found from requested resource "/m
otoconfig/gomez.jsp".>
Size of Env:36
 ModeId:1
 Host:172.20.79.109
 Domain:mphasis
 ModeId:1
 Host:FL08-4492
 Domain:comm.mot.com
 ModeId:1
 Host:mlbp-0090
 Domain:mphasis
 ModeId:1
 Host:mlbp-0101
 Domain:mphasis
 ModeId:1
 Host:172.20.79.74
 Domain:mphasis
 ModeId:1
 Host:MLBP-0097
 Domain:MPHASIS.COM
 ModeId:1
 Host:mjie-0003
 Domain:mphasis
 ModeId:1
 Host:plsu014
0
conversekid
Asked:
conversekid
  • 3
  • 2
  • 2
  • +1
6 Solutions
 
omarfaridCommented:
can you show sample of logs that have more than one date (same date but different lines)?

Also, can you show the egrep command?
0
 
conversekidAuthor Commented:
hi
pls find out.txt as attachmet for log file..

egrep "Nov 12, 2008 |11/12" motoconfig1.out is the command I am using

I am getting output like this:

<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <User object is null. Creating anonymous repository.>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Total menu Items: 1>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Menu Id: 33>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Menu Name: Home>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Parent menu name: null>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Parent menu id: -1>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Description: MOTOCONFIG Tool - Home - $$HOME_PAGE$$>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Location: /motoconfig/Home.do>
<Nov 12, 2008 12:53:07 AM EST> <Error> <HTTP> <BEA-101214> <Included resource or file "/motoconfig/gomez_bd_header.html" not found from requested resource "/motoconfig/gomez.jsp".>
<Nov 12, 2008 12:53:07 AM EST> <Error> <HTTP> <BEA-101214> <Included resource or file "/motoconfig/gomez_bd_footer.html" not found from requested resource "/motoconfig/gomez.jsp".>
[11/12 00:53:07.112 AM] jsp_servlet.__gomez _jspService GOMEZ - Time (ms) To Do A JSP Include To The Login Page: 34
[11/12 00:53:07.113 AM] jsp_servlet.__gomez _jspService GOMEZ - Total Test Time (ms) Observed From App. Side: 53
[11/12 00:53:07.113 AM] jsp_servlet.__gomez _jspService GOMEZ -
[11/12 00:53:22.576 AM] jsp_servlet.__gomez _jspService GOMEZ -
[11/12 00:53:22.583 AM] jsp_servlet.__gomez _jspService GOMEZ - Time (ms) To Get 9iRAC Connection: 7
[11/12 0
out.txt
0
 
ixenator_trialCommented:
In my Linux environment egrep (GNU grep 2.5.3) has a command line option to specify a number of context lines to include.
Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM

Does the following work in your environment?

egrep --after-context=99999999 "Nov 12, 2008 |11/12"  out.txt
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TintinCommented:
Is there a fixed number of lines after the date you want to extract, or is it variable?
0
 
TintinCommented:
Assuming a fixed number of lines (and Solaris 10), you can do

/usr/sfw/bin/ggrep -A 20 "Nov 12, 2008 |11/12" motoconfig1.out
0
 
omarfaridCommented:
I tested this on my system and it works:

$  egrep "Nov 12, 2008|11/12" filename  | more

<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <User object is null. Cre
ating anonymous repository.>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Total menu Items: 1>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Menu Id: 33>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Menu Name: Home>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Parent menu name: null>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Parent menu id: -1>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Description: MOTOCONFIG
Tool - Home - $$HOME_PAGE$$>
<Nov 12, 2008 12:53:07 AM EST> <Debug> <iDen> <000000> <Location: /motoconfig/Ho
me.do>
<Nov 12, 2008 12:53:07 AM EST> <Error> <HTTP> <BEA-101214> <Included resource or
 file "/motoconfig/gomez_bd_header.html" not found from requested resource "/mot
oconfig/gomez.jsp".>
<Nov 12, 2008 12:53:07 AM EST> <Error> <HTTP> <BEA-101214> <Included resource or
 file "/motoconfig/gomez_bd_footer.html" not found from requested resource "/mot
oconfig/gomez.jsp".>
[11/12 00:53:07.112 AM] jsp_servlet.__gomez _jspService GOMEZ - Time (ms) To Do
A JSP Include To The Login Page: 34
[11/12 00:53:07.113 AM] jsp_servlet.__gomez _jspService GOMEZ - Total Test Time
(ms) Observed From App. Side: 53
[11/12 00:53:07.113 AM] jsp_servlet.__gomez _jspService GOMEZ -
0
 
conversekidAuthor Commented:
Hi, omarfarid:
It will give that line..but we require few lines until the date changes again..For example if I am searching for a particular date I want all the lines until the date changes
0
 
TintinCommented:
Does that mean if you specify Nov 12 as the date, you want all lines listed for that day?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now