The UNIX and Linux Forums  


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
extracting text and reusing the text to rename file JohnDS UNIX for Dummies Questions & Answers 7 02-05-2009 03:55 AM
Extracting a part of XML File shridhard Shell Programming and Scripting 9 11-17-2008 07:41 AM
Extracting specific text from a file rahulkav Shell Programming and Scripting 8 10-22-2008 11:34 AM
Extracting a line in a text file terryporter51 Shell Programming and Scripting 5 10-13-2008 07:34 PM
extracting a set of strings from a text file Deanne Shell Programming and Scripting 2 09-21-2007 12:31 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2009
alinaqvi90 alinaqvi90 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 7
Smile extracting part of a text file

Hi guys

So I have a very large log file where each event is logged along with the time that it occurred.

So for e.g. The contents of the file look like:
Code:
...
12:00:07 event 0 happened.
12:01:01 event 1 happened.
12:01:05 event 2 happened.
12:01:30 event 3 happened.
12:02:01 event 4 happened.
12:02:40 event 5 happened.
12:03:40 event 6 happened.
12:04:06 event 6 happened.
...
I want to extract every thing in that file listed between a given start time and an end time.

so some thing like all events between
the first entry of 12:01:00 and the last entry of 12:03:59
and store them in a random text file. Note time stamps can be repeated and therefore I mentioned the first and the last entries.

And not all lines in the log file start with a time stamp. Some lines are just random information about the server etc. But I want to extract those lines as well.

Hope I have clarified my question.

And thanks in advance every one

ali

Use CODE tags when posting code, data or logs for better readability and to preserve formatting like indention etc., ty.

Last edited by zaxxon; 07-21-2009 at 12:25 PM.. Reason: code tags, what else
  #2 (permalink)  
Old 07-21-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
Besides adding code tags moving it to shell scripting area - nothing AIX particular in here.
  #3 (permalink)  
Old 07-21-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,434
You can start from this example:
Code:
awk '{a="file."srand()}/12:01/,/12:03/{print >> a}'  file
  #4 (permalink)  
Old 07-21-2009
edidataguy edidataguy is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 173
Code:
sed  -n '/^12:00/,/^12:03/p' event.log > new_event.log
  #5 (permalink)  
Old 07-21-2009
dukessd dukessd is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2006
Posts: 307
Or a nice simple grep would do it:

Code:
grep -E "12:01|12:02|12:03" <input_text_file_name> > <output_text_file_name>
So here we use the grep command to search for multiple "arguments", delimited by the pipe (|) symbol in the <input_text_file_name> and then redirect with the > to the <output_text_file_name> and then you should have the results you want in the <output_text_file_name> file.

pSeries and AIX Information Center

HTH
  #6 (permalink)  
Old 07-21-2009
edidataguy edidataguy is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 173
Quote:
Originally Posted by dukessd View Post
Or a nice simple grep would do it:

Code:
grep -E "12:01|12:02|12:03" <input_text_file_name> > <output_text_file_name>
So here we use the grep command to search for multiple "arguments", delimited by the pipe (|) symbol in the <input_text_file_name> and then redirect with the > to the <output_text_file_name> and then you should have the results you want in the <output_text_file_name> file.

pSeries and AIX Information Center

HTH
This may not meet all the requirements.
Remember the requirement says:
"""And not all lines in the log file start with a time stamp. Some lines are just random information about the server etc. But I want to extract those lines as well."""
  #7 (permalink)  
Old 07-21-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
Quote:
Originally Posted by edidataguy View Post
This may not meet all the requirements.
Remember the requirement says:
"""And not all lines in the log file start with a time stamp. Some lines are just random information about the server etc. But I want to extract those lines as well."""
yeah it wouldn't and this is more simpler
Code:
grep 12:0[1-3] event.log
Reply

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 12:14 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