help to retrive data from log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to retrive data from log file
# 1  
Old 07-03-2006
help to retrive data from log file

hi

i have following file.
where i m trying to retrive data on latest date.
let us say we are extracting data from this file for Jun 30 where date is highest date in log file.
here i want to take output in other file from first line of Jun 30 to the end of file
[ here i want details also like Genration number and genration date]
in short i want retrive complete data for the latest date in log file.
and latest date is simmilar to the todays date...

i m trying to use grep and sub instr but no sucees.
plz guide me.

Thanks a lot in adavnce
Swapneel


*****************Thu Jun 28 20:06:28 BST 2006***********************************
***
Generation Number : 20062231
Generation Date : 20060629
There are no detail records
*****************Thu Jun 29 23:46:38 BST 2006***********************************
***
Generation Number : 20062231
Generation Date : 20060629
There are no detail records
*****************Fri Jun 30 00:01:19 BST 2006***********************************
***
Generation Number : 20062237
Generation Date : 20060629
There are no detail records
*****************Fri Jun 30 00:01:19 BST 2006***********************************
***
Generation Number : 20062237
Generation Date : 20060630
There are no detail records
# 2  
Old 07-03-2006
Perhaps read backwards from the end of the file until line begins with a "*"....
Code:
tac file1|awk '1;/^*/{exit}'|tac

# 3  
Old 07-03-2006
Code:
$ tac 1.txt | sed -ne '/^\*/ s/\*//g p' | head -n 1

# 4  
Old 07-03-2006
I think the OP wants all data from Jun 30 :

Code:
#!/bin/ksh
awk '{ if (index($0,"***")>0){
         printf("\n%s|",$0)} 
         else{printf("%s|", $0)} 
      }' filename | \
      grep 'Jun 30'  | tr -s '|' '\n' | grep 'Generation'

Without resorting to add-on perl modules(DATE::str2time), I cannot think of a way to find the max date other than
Code:
tail -5 filename

# 5  
Old 07-03-2006
perl

Implying that dates were written in same format:

Code:
$ cat 1.pl
#!/usr/bin/perl -w

open (INPUT, "< logfile");

my $last = '', @to_print = ();
while (<INPUT>) {

    push @to_print, $_;
    if (/^\*{3}/) {
        s/\*//g;
        @to_print = ($to_print[$#to_print]) if $last ne $_;
        $last = $_;
    }
}

for (@to_print) {
    print $_;
}

Code:
$ cat logfile
*****************Thu Jun 28 20:06:28 BST 2006**************************************
Generation Number : 20062231
Generation Date : 20060629
There are no detail records
*****************Thu Jun 29 23:46:38 BST 2006**************************************
Generation Number : 20062231
Generation Date : 20060629
There are no detail records
*****************Fri Jun 30 00:01:19 BST 2006**************************************
Generation Number : 20062237
Generation Date : 20060629
There are no detail records
*****************Fri Jun 30 00:01:19 BST 2006**************************************
Generation Number : 20062237
Generation Date : 20060630
There are no detail records

Code:
$ ./1.pl
*****************Fri Jun 30 00:01:19 BST 2006**************************************
Generation Number : 20062237
Generation Date : 20060629
There are no detail records
*****************Fri Jun 30 00:01:19 BST 2006**************************************
Generation Number : 20062237
Generation Date : 20060630
There are no detail records

# 6  
Old 07-06-2006
Thanks a lot

Thanks a lot for your time and advise

Regards,
Swapneel
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract data from a log file and put it in a file

Hi, I would like to seek your help for a script that will extract data from log file and put it in a file. Sample log file 2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH account: 123456789 aiSessionNumber: 660640464 mapName: xxx to yyy errorDesc: Translation Error:ErrorNumber : 993 ... (2 Replies)
Discussion started by: neverwinter112
2 Replies

2. Shell Programming and Scripting

Data sorting out from log file

I have a logfile looks like this: Received request of type I need two write out every line to a new file if contains to a file called the SID name, like 187175558_xyz.txt Thanks for helping! ---------- Post updated at 08:11 AM ---------- Previous update was at 08:10 AM ---------- I... (7 Replies)
Discussion started by: batka
7 Replies

3. UNIX for Dummies Questions & Answers

How to retrive data from DB(Aqua studio) in CVS format using UNIX script?

I am using aqua studio DB. I need to retrive the data from my database using uxin script in .csv format. i am using select query along with the joins. my o/p in the DB is of the below format. Cycle IDCycle StatusRecord 98N-0000ACV23-3636FCliet Level (Af)Success1689393HF-J7879-09090RCliet Level... (1 Reply)
Discussion started by: Mugivz
1 Replies

4. UNIX for Dummies Questions & Answers

make ls retrive ordered list of elements

Hello friends!! I have a question regarding the use of ls in unix. I have a folder with files: t1.txt t2.txt t3.txt t4.txt ... t10.txt When I make an ls I always get: t10.txt t1.txt t2.txt t3.txt .. t9.txt (2 Replies)
Discussion started by: SaktiPhoenix
2 Replies

5. Shell Programming and Scripting

Range of data from a log file .

I am having a log file in which i need a range of data from specific date range. $cat my.log Jan 07 15:39:03 N/A _M_LocalDirectory listFiles(): listing files from dir Jan 07 15:39:03 N/A _w_fm_log:_f_Push() _w_fm_log_export_ftppush(): Files f Jan 07 05:58:35 N/A _w_fm_log_autoexport ... (6 Replies)
Discussion started by: posix
6 Replies

6. Shell Programming and Scripting

Retrive the value returned by a command excuted in a remote server using ssh

Hello Everybody, I'm facing a weird problem with the awk command. I try to retrieve in a variable the value returned by a simple ls command. ls /export/home/tmp |tail -1 return a good value (the name of the . But When I try to execute the same command in a remote server using ssh as... (2 Replies)
Discussion started by: Jabarod
2 Replies

7. Shell Programming and Scripting

retrive value from a file

hi i am new to shell scripting i have a properties file like hs=abc hs1=def hs2=ghi now i want to retrive each value and assign it to a variable like var1 = abc please help (7 Replies)
Discussion started by: satish@123
7 Replies

8. Shell Programming and Scripting

retrive lines from a file using AWK command

Dear friends, please tell me how to get some required lines from a file and write to another file using AWK command. i.e., if a file contains, abcdefghigk 12345 lmnopqrstuv 678910 wxyz please tell me how to get lines(line count is always 2 and it's contineous) mentioned in blue... (1 Reply)
Discussion started by: swamymns
1 Replies

9. Shell Programming and Scripting

to retrive data that appear only once in a file.

hi, I need to get the list of functions that are used more than once in a file list. Thanks in advance (1 Reply)
Discussion started by: anibu
1 Replies

10. UNIX for Advanced & Expert Users

Retrive deleted file's info

I have shell script which reads files, stores its data into Oracle and then deletes tht file. now i want to know creation date and time of deleted files. can we do this? if yes then how? (4 Replies)
Discussion started by: asmita
4 Replies
Login or Register to Ask a Question