LinuxQuestions.org
Review your favorite Linux distribution.
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 03-26-2009, 06:32 AM   #1
Ujjain
Member
 
Registered: Mar 2009
Posts: 33

Rep: Reputation: 15
How do I get lines 30.000 to 40.000 from an Apache access_log file?


I am looking to run Webalizer between hours 14:00 and 15:00 yesterday. I can search the specific line numbers for 14:00 and 15:00 if that's easier.

Unfortunately I only have log files for a complete day, which are 2GB, I need to have the logs for specific times.

If you require any extra information, please let me know.
 
Old 03-26-2009, 06:44 AM   #2
reptiler
Member
 
Registered: Mar 2009
Location: Hong Kong
Distribution: Fedora
Posts: 184

Rep: Reputation: 42
There may be a better way, but you could combine head and tail to cut the output.
Code:
head -n 40000 access_log | tail -n 10000
head will pass the first 40000 lines of the log to tail, which then outputs the last 10000, thus effectively outputting lines 30001 to 40000.
 
Old 03-26-2009, 06:49 AM   #3
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Have you looked at awk?

Code:
awk 'NR > 30000 && NR < 40000' file
will print lines 30000-40000, not sure if that's quicker or slower than using head/tail.

If the lines contain timestamps, awk could also be used to find the lines between any given times, so that gives you more flexibility. Check the man page for syntax.
 
Old 03-26-2009, 07:19 AM   #4
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
Using sed:
Code:
sed -n "30000,40000p" file
 
Old 03-26-2009, 07:52 AM   #5
Ujjain
Member
 
Registered: Mar 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Thanks for your suggestions! They are all great, but I guess the 'sed' tool is designed for this and therefore the best and fastest solution!
Could you also help me find the easiest way to find the linenumber for a specific time in the Apache logs? The end-result should be an Apache file with logs from 14:00 to 15:00 of yesterday.
 
Old 03-27-2009, 05:37 AM   #6
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
If you know the format of data/time in log files you can run grep -n for it. Full command to get line number for a time would be:
Code:
grep -m 1 -n "your time" log_file|cut -f 1 -d ":"
 
  


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
LXer: 24,000,000 Google hit for I HATE WINDOWS LXer Syndicated Linux News 0 05-04-2007 03:33 PM
LXer: SugarCRM Announces 1,000 Customers and 1,000,000 Open Source Downloads as Momentum for Open Source Applications Grows LXer Syndicated Linux News 0 12-19-2006 05:33 AM
1,000,000,000 PCs by 2010 masand Linux - News 4 11-01-2004 01:55 AM
IBM Contributes 500,000 Lines Of Code To Apache jamaso General 2 08-04-2004 11:58 AM

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

All times are GMT -5. The time now is 04:49 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
Open Source Consulting | Domain Registration