Range of records using comparision \awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Range of records using comparision \awk
# 1  
Old 08-02-2010
Range of records using comparision \awk

Hi Gurus,
I have to fetch the records from a logs as per the time stamp . I am comfortable to use awk and sed in the script . But the logic to fetch the records as per comparison is the problem.
Code:
$cat my_log.log
 <Jul 30, 2010 7:01:12 AM EEST> <Error> <WebLogicServer> 
 <Jul 30, 2010 8:04:12 AM EEST> <Error> <WebLogicServer> 
 <Jul 30, 2010 8:13:12 AM EEST> <Error> <WebLogicServer> 
 <Jul 30, 2010 9:02:03 AM EEST> <Error> <WebLogicServer> 
 <Jul 30, 2010 9:13:13 AM EEST> <Error> <WebLogicServer> 
 <Jul 30, 2010 9:56:13 AM EEST> <Error> <WebLogicServer>

If my input start time is 8:10 AM and end time is 9:10 AM , How could we'll able to fetch the records during that time.Smilie Cause the pattern of time is not available in the file.
# 2  
Old 08-02-2010
Code:
$> cat infile
 <Jul 30, 2010 7:01:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:04:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:09:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:10:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:11:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:13:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:13:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:02:03 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:09:13 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:10:13 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:11:13 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:13:13 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:56:13 AM EEST> <Error> <WebLogicServer>
$> awk -F"[ \t]+|:" '$8 == "AM" && ( $5 == 9 && $6 <= 10 || $5 == 8 && $6 >= 10 )' infile
 <Jul 30, 2010 8:10:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:11:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:13:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 8:13:12 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:02:03 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:09:13 AM EEST> <Error> <WebLogicServer>
 <Jul 30, 2010 9:10:13 AM EEST> <Error> <WebLogicServer>

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-02-2010
Code:
#!/usr/bin/perl
open (FH,"<","/home/pravin/mylog") || die " cannot open file \n";;
$start_time=shift;
$end_time=shift;

$start_time_hr=`echo $start_time | cut -d ":" -f1` * 60;
$start_time_min=`echo $start_time | cut -d ":" -f2` + $start_time_hr;

$end_time_hr=`echo $end_time | cut -d ":" -f1` * 60;
$end_time_min=`echo $end_time | cut -d ":" -f2` + $end_time_hr;

while (<FH>) {
chomp;
if (/\<(.+?)\s(\d{1,2})\:(\d{1,2})\:\d{1,2}/) {
$fmins=$2 * 60 ;
$fmins=$fmins + $3;
if ( $fmins >= $start_time_min && $fmins <= $end_time_min ) {
print $_,"\n";
}
}
}
close(FH);

# 4  
Old 08-02-2010
Thanks Zaxxon for your reply.. i got some good idea.. from the script.
Also thanks to Pravin27 .. I've not tested the perl Script , cause not much idea in perl..
But interested to learn it. .Novice in perl.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Clean values in range of duplicate records

Dear Gents, Could you please help me to solve this problem. I am getting the average of a column for same duplicate records in this case locate in column 1. The average is computed from column 5 from all duplicate records in column 1. Normallly the values in column 5 is constant so the... (3 Replies)
Discussion started by: jiam912
3 Replies

2. Shell Programming and Scripting

awk comparision between 2 files and substitution in third

Hi All, I have two files in the following format. File 1 : 1044|1|20121031|2910039.4|MR|201210|G1044|E 1082|2|20121031|1664662.84|MR|201210|G1082|E 1696|3|20121031|190801.5|MR|201210|G1696|E 1824|4|20121031|196350|MR|201210|G1824|E 1900|5|20121031|221447.8|MR|201210|G1900|E File 2 :... (7 Replies)
Discussion started by: nua7
7 Replies

3. Shell Programming and Scripting

Awk comparision

Hi Everyone I am new to Unix shell scripting Can anyone please explain me in detail how this command works awk -F@ 'NR==FNR{A=$2;next}$3 in A{$3=A}1' file2 file1 The above command I got it from this forum, but unable to implement it as I am not getting how this works:mad: I... (3 Replies)
Discussion started by: Vijay90
3 Replies

4. Shell Programming and Scripting

awk field range

I was reading about different methods of awk field ranges. Does the second method have any advantage? Its quite a bit longer so I am wondering what the advantage is. awk '{for(i=5;i<=9;i++)printf "%s ",$i;print ""}' filename ... (2 Replies)
Discussion started by: cokedude
2 Replies

5. Shell Programming and Scripting

awk: string followed by tab comparision

Hi all, Currently i am using if( $0~/ NOT / && $0~/ NULL /) { ................. } to check if the input record contains "NOT" and "NULL". But in some cases "NOT" and "NULL" are preceded and followed by tab. How do i find compare for these fields as well? (3 Replies)
Discussion started by: ysvsr1
3 Replies

6. Shell Programming and Scripting

File comparision with AWK / SED

Hi all I need to compare two separate product lists that are changed weekly. New products are added, old products are removed and prices change. I have found various Windows programs that do this function but it's not as clean as I like and just wondered if there was a simpler way with... (1 Reply)
Discussion started by: mrpugster
1 Replies

7. Shell Programming and Scripting

range patterns in awk

Hi All, I am new to awk command and I had a question in using it. I want to filter a code file and print specific functions (that contain menu word in the function name). for example, if the file has: function menu1() { } function f2() { } function menu3() { }so I want... (5 Replies)
Discussion started by: ghoda2_10
5 Replies

8. Shell Programming and Scripting

awk search within a range.

I have this kind of file ABC UUIIIIIIIIIIII , HJHKJKL XYZ HHJJJJJJMMM ABC BBOOIO, PPLIOJK XYZ NMJKJKK ABC MMMM ABC OPOPO XYZ LLKLKLL I need to get all data from ABC till XYZ so output should be UUIIIIIIIIIIII (6 Replies)
Discussion started by: dinjo_jo
6 Replies

9. Shell Programming and Scripting

range in if using awk

Hi All, I would like to assign the following values to each column in my file. if $i is between 1 and -1 (ie -1 < $i < 1) then print A; if $i is between -2 and -1 && 1 and 2 (ie. -2 < $i < -1 && 1 < $i < 2) then print B; if $i is between -3 and -2 && 2 and 3 (ie. -3 < $i < -2 && 2 < $i < 3)... (1 Reply)
Discussion started by: Fredrick
1 Replies

10. UNIX for Dummies Questions & Answers

Number comparision in AWK

Hi, I have a file like this. "2006","10",25,"U","1129","32","C",0,0,0,0,0,0,0,0,0,0,0,0,352,16,4,0,0,0,0,0,"80",,1 "2006","11",25,"U","1148","32","C",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"80",,2 "2006","14",25,"U","1149","10","C",0,0,0,0,0,0,0,0,0,0,0,0,560,12,0,0,0,0,0,0,"80",,3... (1 Reply)
Discussion started by: vskr72
1 Replies
Login or Register to Ask a Question