Grep content between timestamp

Hi all,

I have a file which will be updated every half an hour and time stamp will be printed in the beginning of the updation. i just want to grep the content between every hoalf an hour.

Pls help me on this issue. how to grep contents between tim stamp?

Ex of file:

29/09/2010 00:30
callingPtyConvE 0       0       0       0      
cpartyId        0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
objectClass     0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
cpartyName      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
entryACI        0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
dibAttributeTyp 0       0       0       0      
configType      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
objectClass     0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
dibAttrTypeEntr 0       0       0       0      
attributeId     0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
objectClass     0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
attributeName   0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
syntaxType      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
location        0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
singleValue     0       0       0       0       0       0       0       0       0       0       0       0       0       0       0   
    0      
userAttr        0       0       0       0       0       0       0       0       0       0       0       0       0       0       0 

29/09/2010 01:00

cpartyName      0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
entryACI        0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
dibAttributeTyp 0       0       0       0      
configType      0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
objectClass     0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
dibAttrTypeEntr 0       0       0       0      
attributeId     0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
objectClass     0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
attributeName   0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
syntaxType      0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
location        0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
singleValue     0       0       0       0       0       0       0        0       0       0       0       0       0       0       0   
    0      
userAttr        0       0       0       0       0       0       0        0       0       0       0       0       0       0       0 

Thanks

Steve

awk '/29\/09\/2010 01:00/,/userAttr/' infile

Hi rdcwayx,

I want to take the output for every half an hour .. and i want to put script in crontab also.. i'm using solaris system.

Pls help !!

Thanks

Steve

not clear.

From your sample , I don't know what output you need to get every half an hour.

Hi,

I mean .. i want to take the content between the timestamp of every half an hour and put it into new file.

Hope u understand.

Thanks

Steve

I am a little understand your expect now.

For example, the cornjob running at 29/09/2010 00:40, then you need capture the data in 29/09/2010 00:30 block. Because at that time, 01:00 data are still not ready.

Is that correct?

Exactly ... but i want to grep the content between 00:00 to 00:30 hours...
next 00:30 to 01:00
01:00 to 01:30
01:30 to 02:00 etc...

you are correct !!

Pls help !!

Pls somebody help on this issue..

Thanks in Advance.

Regards,
Steve

-----

Hi rdcwayx,

You gave me the below script.. its greping only the mentioned time. but i want to do the same for all the hours in default.

Pls help

awk '/29\/09\/2010 01:00/,/userAttr/' infile

Below code could help but only where there are 2 time stamps in the inputfile

sed -n '/\([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]\)/,/1/p' inputfile
#!/bin/sh
sed -n '/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/p' time.txt | sed -e 's/ /./' -e 's/\//./g' > time_stamps.txt
last_time_stamp=`sed -n '$'p time_stamps.txt`
sed -n '/'$last_time_stamp'/,$'p time.txt > last_half_hour.txt
sed -i '1,2d' last_half_hour.txt

Hey Steve,
The Above small script will do ur job...
the file "last_half_hour.txt" will contain the entries for last half an hour...
do some thing to rename "last_half_hour.txt" to your desire.
So when you set this as a cronjob the file won't be overwritten..:slight_smile:
Test it man, it will work for files with any number of time stamps...

Hi Kesavan,

Pls telme where you mention the input file in your script?

Thanks

Steve

time.txt is the input file........:slight_smile:

Thanks kesavan .. Its working fine..

But one small bug is thr.. its taking the current timing content..

Ex: If now system time is 14:10. script should grep content between 13:30 to 14:00

but your script is taking 14:00 content.. pls modify as per this need and telme .

Thanks a Lot...

Steve

---------- Post updated at 06:44 PM ---------- Previous update was at 06:29 PM ----------

HI kesavan ,

Last line of your script is not working .. pls check...

LGS-HF2-2$ sed -i '1,2d' last_half_hour.txt 
sed: illegal option -- i

-i option is for in place edition without redirection
but i don't get why it is not working for you...
anyway try this one...

#!/bin/sh
sed -n '/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/p' time.txt | sed  -e 's/ /./' -e 's/\//./g' > time_stamps.txt
last_time_stamp=`sed -n '$'p time_stamps.txt`
sed  '$'d time_stamps.txt > temp0.txt
mv temp0.txt time_stamps.txt
last_time_stamp1=`sed -n '$'p time_stamps.txt`
sed -n '/'$last_time_stamp1'/,/'$last_time_stamp'/'p time.txt > last_half_hour.txt
sed  '1'd last_half_hour.txt > temp.txt
sed  '$'d temp.txt > temp1.txt
mv  temp1.txt last_half_hour.txt

Now check the "last_half_hour.txt" output file :)....

Thanks Kesavan !!!!!

Its working fine now.. :b:

Tanks a lot.. :slight_smile:

Steve

You are welcome...

Hi Kesavan,

Can you pls explain your below script? thanks

#!/bin/sh
sed -n '/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/p' time.txt | sed  -e 's/ /./' -e 's/\//./g' > time_stamps.txt
last_time_stamp=`sed -n '$'p time_stamps.txt`
sed  '$'d time_stamps.txt > temp0.txt
mv temp0.txt time_stamps.txt
last_time_stamp1=`sed -n '$'p time_stamps.txt`
sed -n '/'$last_time_stamp1'/,/'$last_time_stamp'/'p time.txt > last_half_hour.txt
sed  '1'd last_half_hour.txt > temp.txt
sed  '$'d temp.txt > temp1.txt
mv  temp1.txt last_half_hour.txt
my ($pre,$cur);
while(<DATA>){
  if (/([0-9]{2})\/([0-9]{2})\/([0-9]{4})\s+([0-9]{2}):([0-9]{2})/){
    $temp = $3."_".$2."_".$1."_".$4."_".$5;
    if($.==1){
       $cur = $temp;
       $pre = $temp;
    }
    else{
      $cur = $temp;
      my $tmp = ${pre}."-".$cur.".leo";
      open FH,">$tmp";
      print FH @{$hash{$pre}};
      close FH;
      @{$hash{$temp}}=(@{$hash{$pre}});
      $pre = $temp;
    }
    next;
  }
  else{
    push @{$hash{$temp}},$_;
  }
}
my $temp=${pre}."_now.leo";
open FH,">$temp";
print FH @{$hash{$pre}};
close FH;
__DATA__
29/09/2010 00:30
line 1
line 2
29/09/2010 01:00
line 3
line 4
29/09/2010 01:30
line 5
line 6
29/09/2010 02:30
line 7
line 8