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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrive value from a file satish@123 Shell Programming and Scripting 7 05-17-2008 05:57 AM
retrive lines from a file using AWK command swamymns Shell Programming and Scripting 1 05-04-2008 06:47 PM
to retrive data that appear only once in a file. anibu Shell Programming and Scripting 1 10-26-2007 07:54 AM
Retrive deleted file's info asmita UNIX for Advanced & Expert Users 4 03-26-2007 10:36 PM
Using loop reading a file,retrieving data from data base. Sonu4lov Shell Programming and Scripting 1 01-18-2007 11:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-03-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Perhaps read backwards from the end of the file until line begins with a "*"....
Code:
tac file1|awk '1;/^*/{exit}'|tac
Reply With Quote
  #3 (permalink)  
Old 07-03-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
Code:
$ tac 1.txt | sed -ne '/^\*/ s/\*//g p' | head -n 1
Reply With Quote
  #4 (permalink)  
Old 07-03-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,854
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
Reply With Quote
  #5 (permalink)  
Old 07-03-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
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
Reply With Quote
  #6 (permalink)  
Old 07-06-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
Thanks a lot

Thanks a lot for your time and advise

Regards,
Swapneel
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0