How to extract certain part of log file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract certain part of log file?
# 1  
Old 05-24-2008
Question How to extract certain part of log file?

Hi there,

I'm having some problem with UNIX scripting (ksh), perhaps somebody can help me out?

For example:
------------
Sample content of my log file (text file):
--------------------------------------
File1: ....
info_1 ...
info_2 ...
info_3 ...

File2: ....
info_1 ...
info_2 ...
info_3 ...

File3: ....
info_1 ...
info_2 ...
info_3 ...

...Etc

I'm having a problem to extract relevant information from a portion part of the log file. For example, how can I extract all relevant information for "File2" only (including info_1, info_2 and info_3)?

So if the desired output should be:
---------------------------------
File2: ....
info_1 ...
info_2 ...
info_3 ...

My scripting skill still not very advance. so any help or suggestion would be much appreciated.

Thanks.
# 2  
Old 05-24-2008
Code:
</> cat "your log.file" | sed -n '/^File2/,/^File3/p' | sed '$d'

# 3  
Old 05-24-2008
Code:
awk 'BEGIN{RS=""} /File2/' file

# 4  
Old 05-24-2008
Hi All,

Thanks a lot for your response. Appreciate it.

But given another situation such as below, is it possible to extract portion of information based on key word: PROBLEM001, providing this is a unique key word. Or can I use the same method mentioned earlier? Please advice. Thanks.

File1: ....
info_1 ...
info_2 ...
info_3 ...

File2: ....
info_1 ... PROBLEM001
info_2 ...
info_3 ...

File3: ....
info_1 ...
info_2 ...
info_3 ...

File4: ....
info_1 ... PROBLEM001
info_2 ...
info_3 ...

...
...
Etc

OUTPUT:
--------
File2: ....
info_1 ... PROBLEM001
info_2 ...
info_3 ...

File4: ....
info_1 ... PROBLEM001
info_2 ...
info_3 ...
# 5  
Old 05-24-2008
Struglling to post a thread.. donno how to do it?

PLz assist guys n gals... i wanna post a thread but dont kno exactly ho to do it... have some doubts regarding unix.
# 6  
Old 05-24-2008
Quote:
Originally Posted by superHonda123
Or can I use the same method mentioned earlier? Please advice. Thanks.
Yes, same thing. You insert the key word between /keyWord/

Code:
awk 'BEGIN{RS="";ORS="\n\n"} /PROBLEM001/' file

# 7  
Old 05-24-2008
removing my quote because Ripat had already answered
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract part of string from all log files.?

Hi All, Let us say we have 5 log files, extract the data from all log files and save the output in a file. home/log/first.log home/log/second.log home/log/third.log home/log/four.log home/log/five.log I want to extract the following text from the log files and save the output in a file.... (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

2. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies

3. Programming

Extract part of an archive to a different file

I need to save part of a file to a different one, start and end offset bytes are provided by two counters in long format. If the difference is big, how should I do it to prevent buffer overflow in java? (7 Replies)
Discussion started by: Tribe
7 Replies

4. Shell Programming and Scripting

Extract the part of sequences from a file

I have a text file, input.fasta contains some protein sequences. input.fasta is shown below. >P02649 MKVLWAALLVTFLAGCQAKVEQAVETEPEPELRQQTEWQSGQRWELALGRFWDYLRWVQT LSEQVQEELLSSQVTQELRALMDETMKELKAYKSELEEQLTPVAEETRARLSKELQAAQA RLGADMEDVCGRLVQYRGEVQAMLGQSTEELRVRLASHLRKLRKRLLRDADDLQKRLAVY... (8 Replies)
Discussion started by: rahim42
8 Replies

5. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

6. Shell Programming and Scripting

Getting the date part from the log file.

Hi, I have a script that runs to generate a log file which is in this format: Start: Friday, April 29, 2011 18:30 User : Host : Database : I need to write a script that reads this log file (RUN.LOG) and rename the existing log file... (7 Replies)
Discussion started by: ashok@119
7 Replies

7. Shell Programming and Scripting

Get a part of a String from a log file

Hey there, I'm searched for one day your forum for a similar solution. Didn't find one, sorry :( Now here is what I'm searching for. I have the following multiple lines from a log (Edit: log name is SystemOut.log - this is not my day. I Apologize): 000042e2 1_BLA_Yab I logging.LogInfo... (5 Replies)
Discussion started by: nobodyhere
5 Replies

8. Shell Programming and Scripting

extract part of text file

I need to extract the following lines from this text and put it in different files. From xxxx@gmail.com Thu Jun 10 21:15:46 2010 Return-Path: <xxxxx@gmail.com> X-Original-To: xxx@localhost Delivered-To:xxxx@localhost Received: from ubuntu (localhost ) by ubuntu (Postfix) with ESMTP... (11 Replies)
Discussion started by: waxo
11 Replies

9. Shell Programming and Scripting

Tailing last modified part of log file

I have a log file which contains data like this This log file is updated twice a day at 7am and 6pm, I want a script(which i will make run at 7:10am and 6:10pm) which should fetch only the last appended lines since last update.. I mean.. if i execute the script at 7.10am 3/3/2010 it... (4 Replies)
Discussion started by: user__user3110
4 Replies

10. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies
Login or Register to Ask a Question