LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-13-2006, 10:31 AM   #1
overpeer
LQ Newbie
 
Registered: Aug 2005
Location: Valencia (Spain)
Distribution: Gentoo
Posts: 9

Rep: Reputation: 0
Extract log FROM - TO with shell commands


Hi all!

I want extract a portion of log file, from one timestamp to other timestamp with a shell script o a simple shell command.

This logs files have a lot of megabytes, and stand in a remote machines connected with a GPRS network to me, for it if i need read the log ... is expensive and slower get the entire log file, if i could extract a portion and compress it with gzip for download ... huummm i will be very happy

The problem is, that no all lines of log have a timestamp (yes, is a desing error ... but ... i'm only the sysadmin ... not the developer :P ), then if i filtering for example with 'cat logfile.log | grep 20060309145920 > piece.log' then the lines without timestamp dont appear

Some idea??

A lot of thanks
 
Old 03-13-2006, 11:00 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I want
Would be nice if next time you showed us what you tried. Bein admin and all you should know at least one shell to script with...


The problem is, that no all lines of log have a timestamp
...but since log is linear it doesnt matter, right? Grep for the first timestamp and note the line (-m 1 -n). Same for last line (or something from wc -l). Now feed the first and second number and the filename to sed:
Code:
sed -n ${first},${last}p $filename
and you have the chunk on stdout. Shouldnt be too hard to make a script out of that.


for example with 'cat logfile.log | grep 20060309145920
You *do not need* cat to grep: "grep searchterm filename".
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
Log all commands used in a Session....how? vous Linux - Security 2 03-20-2005 05:32 AM
how to extract certain lines from a log file Avatar Linux - Newbie 3 02-11-2005 09:51 AM
linux shell - extract filename from and song info from text database d003 Programming 1 07-23-2003 04:06 AM
accepting root passwd from UI and passing it to a shell script to extract a rpm rameshvl Linux - Software 4 03-18-2003 12:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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