View Single Post
  #1  
Old 14th February 2013, 06:41
bejaia bejaia is offline
Junior Member
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Capture a log portion closest of 2 hours

Hello,

./my_script.sh works without brackets.
I want to modify ./my_script.sh when in the server.log the date and hour are between brackets like that [24/01/2013 09:10]
I tried in vain certains modifications.
Can you help me ? Thank you for your help.


Code:
cat server.log
Code:
error jonas
aaaaaaaaaaaaaa
bbbbbbbbbbbbb
cccccccccccc
24/01/2013 09:10 sssssssss
sssssssssssssss
cccccccccccccc
nnnnnnnnnnnnn
24/01/2013 10:10 uuuuuuuuu
uuuuuuuuuuuuuuu
jjjjjjjjjjjjjj
ttttttttttttttt
mmmmmmmmmmmmm
24/01/2013 10:30 oooooooooo
oooooooooooo
sssssssssssss
qqqqqqqqqqq
24/01/2013 10:45 vvvvvvvvv
vvvvvvvvv
sssssssss
wwwwwwwwww
my_script.sh

Code:
file=$1
if [ -f $file.gz ]
     then command="gunzip -c"
     else command=cat
fi
$command $file | awk -F"[/ ]" -v S="24/01/2013 10:10" -v E="24/01/2013 10:30" '
function dcmp(b) {
  if($3>b[3])return  1;
  if($3<b[3])return -1;
  if($2>b[2])return  1;
  if($2<b[2])return -1;
  if($1>b[1])return  1;
  if($1<b[1])return -1;
  if($4>b[4])return  1;
  if($4<b[4])return -1;
  return 0;
}
BEGIN{split(S, ds, "[/ ]"); split(E, de, "[/ ]") }
/^[0-9][0-9]\/[0-1][0-9]\/[0-9][0-9][0-9][0-9] / {
   if(s&&dcmp(de)>=0) {print; exit}
   if(!s&&dcmp(ds)<=0) {f=x;w=1}
   if(!s&&dcmp(ds)>=0) {printf "%s",f; f=x; s=1 }
}
!w&&!s {f=f $0 "\n"}
s'
Reply With Quote
Sponsored Links