extracting part of a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting part of a text file
# 1  
Old 07-21-2009
Bug 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 Smilie

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  
Old 07-21-2009
Besides adding code tags moving it to shell scripting area - nothing AIX particular in here.
# 3  
Old 07-21-2009
You can start from this example:
Code:
awk '{a="file."srand()}/12:01/,/12:03/{print >> a}'  file

# 4  
Old 07-21-2009
Code:
sed  -n '/^12:00/,/^12:03/p' event.log > new_event.log

# 5  
Old 07-21-2009
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  
Old 07-21-2009
Quote:
Originally Posted by dukessd
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  
Old 07-21-2009
Quote:
Originally Posted by edidataguy
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting and copying text from one file to another

Helooo, So I have a .fasta file (a text file with sequence data) which looks like this, with just over 3 million lines of data. >TCONS_00000001 gene=XLOC_000001 AATTGTGGTGAAATGACTTCTGTTAACGGAGACATCGATGATTGTTGTTACTATTTGTTCTCAGGATTCA... (8 Replies)
Discussion started by: 4galaxy7
8 Replies

2. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (0 Replies)
Discussion started by: csim_mohan
0 Replies

3. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

help extracting text from file

Hello I have a large file with lines beginning with 552, 553, 554, below is a small sample, I need to extract the data you can see below highlighted in bold from this file on the same location on every line and output it to a new file. Thank you in advance for any help 55201KL... (2 Replies)
Discussion started by: firefox2k2
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting the last column of a text file

I would like to extract the last column of a text file but different rows of the text file have different numbers of columns. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

7. Shell Programming and Scripting

Extracting a part of XML File

Hi Guys, I have a very large XML feed (2.7 MB) which crashes the server at the time of parsing. Now to reduce the load on the server I have a cron job running every 5 min.'s. This job will get the file from the feed host and keep it in the local machine. This does not solve the problem as... (9 Replies)
Discussion started by: shridhard
9 Replies

8. Shell Programming and Scripting

Extracting specific text from a file

Dear All, I have to extract a a few lines from a log file and I know the starting String and end string(WHich is same ). Is there any simplere way using sed - awk. e.g. from the following file -------------------------------------- Some text Date: 21 Oct 2008 Text to be extracted... (8 Replies)
Discussion started by: rahulkav
8 Replies

9. Shell Programming and Scripting

Extracting a line in a text file

If my file looks like this…. 10 20 30 and I want to take each line individually and put it in a variable so it can be read later in it's on individual test statement, how can I do that? I guess what I'm asking is how can I extract each line individually. Thanks (5 Replies)
Discussion started by: terryporter51
5 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question