The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
NFS Mount Points davidra UNIX for Dummies Questions & Answers 1 11-28-2007 04:49 PM
Gnuplot question: how to plot 3D points as colored points in map view? karman UNIX and Linux Applications 0 09-24-2007 07:03 AM
how to run prog bet to break points useless79 High Level Programming 1 09-07-2007 08:42 AM
tar using mount points legato UNIX for Dummies Questions & Answers 3 03-30-2005 11:54 PM
mount points manderson19 UNIX for Advanced & Expert Users 3 04-29-2002 03:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-07-2008
openspark openspark is offline
Registered User
  
 

Join Date: Aug 2008
Location: New Jersey
Posts: 22
How can I get entries between two points

Hi,

I am trying to write a script to get entries between two points lets say start and end points from a log file,

the log file time format is as follows

Start - 07/Aug/2008:18:26:43
End - 07/Aug/2008:19:36:43

I tried using the following awk command but it couldnt pick up the entries in between

awk /'06\/Aug\/2008:18:26:43/,/06\/Aug\/2008:18:36:43/' request.log

Thanks
  #2 (permalink)  
Old 08-07-2008
sudhamacs sudhamacs is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 98
use sed :

sed -n '/06\/Aug\/2008:18:26:43/,/06\/Aug\/2008:18:36:43/ p' request.log
  #3 (permalink)  
Old 08-07-2008
MikaBaghinen MikaBaghinen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
or without sed, but 6 lines instead of one:

#! /usr/bin/ksh
#
#
#
#
TOT_LENGTH=`wc -l request.log | awk '{print $1}' | tr -d " "`
START_LINE=`grep -n "Start - 07/Aug/2008:18:26:43" request.log | cut -f1 -d:`
STOP_LINE=`grep -n "End - 07/Aug/2008:19:36:43" request.log | cut -f1 -d:`
LAST_PART=`expr $TOT_LENGTH - $START_LINE`
DIFF_START_END=`expr $STOP_LINE - $START_LINE`
tail -$LAST_PART request.log | head -$DIFF_START_END
###
  #4 (permalink)  
Old 08-07-2008
openspark openspark is offline
Registered User
  
 

Join Date: Aug 2008
Location: New Jersey
Posts: 22
Exclamation

Hi,
Thanks for your replies, actually I tried both the methods but it doesnt seem to pick up the log entries between the start and end times, The above code

Quote:
Originally Posted by MikaBaghinen View Post
or without sed, but 6 lines instead of one:

#! /usr/bin/ksh
#
#
#
#
TOT_LENGTH=`wc -l request.log | awk '{print $1}' | tr -d " "`
START_LINE=`grep -n "Start - 07/Aug/2008:18:26:43" request.log | cut -f1 -d:`
STOP_LINE=`grep -n "End - 07/Aug/2008:19:36:43" request.log | cut -f1 -d:`
LAST_PART=`expr $TOT_LENGTH - $START_LINE`
DIFF_START_END=`expr $STOP_LINE - $START_LINE`
tail -$LAST_PART request.log | head -$DIFF_START_END
###
Gives a syntax error

I tried using the following methods also but without any result

1. awk /'06\/Aug\/2008:18:26:43/,/06\/Aug\/2008:18:36:43/' request.log

2. sed -n -e '/06\/Aug\/2008:18:26:43/,/06\/Aug\/2008:18:36:43/' -e '/06\/Aug\/2008:18:36:43/q' request.log

3. awk '/06\/Aug\/2008:18:26:43/&&f{exit}f;/06\/Aug\/2008:18:36:43/{f++}' request.log

A sample log entry is as follows

198.232.219.21 - ukla_portal_23@ukla.com [07/Aug/2008:14:51:23 -0400] "GET HTTPS://modulemgr.stage.ukla.com/mys...e_services.gif HTTP/1.1" 200 148
198.232.219.21 - ukla_portal_23@ukla.com [07/Aug/2008:14:55:23 -0400] "GET HTTPS://modulemgr.stage.ukla.com/mys...vice_green.gif HTTP/1.1" 200 3168
198.232.219.21 - ukla_portal_23@ukla.com [07/Aug/2008:15:05:23 -0400] "GET HTTPS://modulemgr.stage.ukla.com/mys.../gray_line.gif HTTP/1.1" 200 371

The above is just a sample and there are close to 10000 lines in a log file in an hour.

Please help me in finding the entries between two points (Start - End )

Your help is greatly appreciated !

Thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0