LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-26-2006, 03:09 PM   #1
tonan
Member
 
Registered: Nov 2003
Location: india, New Delhi
Distribution: Red Hat Linux
Posts: 62

Rep: Reputation: 16
Question Split a section from the log file


Hi Friends,

I have tried searching using man and in this forum, but i was not able to find the exact stuff, i want to split out a section of the log file with a given pattern. Say i would like to split a section with the date stamp of 22/11/06 - 23/11/06 How can this be done, do i have to use pipes with commands like head and tail, i have tried out the combination of head and tail but i am not able to set the pattern using grep. I tried but it splits the file into small chucks of fixed size, can anyone tell me how to split out a section into a new file from a 2 GB log file.

Thanks & Regards
 
Old 11-26-2006, 03:35 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Can you provide an example line in the logfile (so we can see the date format)?
 
Old 11-26-2006, 03:53 PM   #3
tonan
Member
 
Registered: Nov 2003
Location: india, New Delhi
Distribution: Red Hat Linux
Posts: 62

Original Poster
Rep: Reputation: 16
Example line

[11/23/06 14:32:52] [error] [client 132.143.305.24] client denied by server configuration:

This is an example line.
 
Old 11-26-2006, 04:36 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
since you want two consecutive days, why not just do this:
Code:
grep -e '^.11/21/06' -e '^.11/22/06' log_file > new_file
...which will create new_file with the contents from the specified dates.
 
Old 11-26-2006, 05:22 PM   #5
tonan
Member
 
Registered: Nov 2003
Location: india, New Delhi
Distribution: Red Hat Linux
Posts: 62

Original Poster
Rep: Reputation: 16
Smile Thanks Man, will try it out and let you know

Thankyou for the suggestion, i shall sure try it out, but there is a small catch.

If i do a grep on such a huge file like 2 GB log file, wont there be a lot of CPU utilization. Can the box hang due to it.

Well i shall surely let you know how it wnt.

Regards
 
Old 11-26-2006, 06:15 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
you could prefix the command with nice, which will give it a lower priority for CPU usage. Depending on your hardware, the IO will probably cause more load - the CPU is also used for IO, you can't nice that since it is done by the kernel.

However, whatever method you use, you'll HAVE to read the data from the file, so this is unavoidable. The only thing you can do it make sure you choose a method which reads the file once. The grep command above should only read the file once.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Split Up log activity from Remote Hosts king0770 Linux - Server 0 10-12-2006 05:05 PM
How to split file , .. awk or split ERBRMN Linux - General 9 08-15-2006 01:02 AM
mysqldump : Can I split the file up to 2GB max per file? Swakoo Linux - General 10 10-17-2005 05:13 AM
Split the Newb Section sKiBa LQ Suggestions & Feedback 21 07-06-2004 04:13 AM
RPM Spec file creation: %file section question davidas Linux - Newbie 0 03-16-2004 11:36 PM


All times are GMT -5. The time now is 12:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration