Specific range of records
I am having a log file where there is some discontinuous of dates are there but if i go for range of date to find the records, if is some date is missing the result is displaying full file list( Start date to end of file ) How could i restrict the result upto the mentioned date range.
Code:
$cat sample.log |
Your problem is quite obvious, and won't be trivially solved
with sed. I'd recommend using awk for this job, which will give you the possibility to check for the "range" numerically with a -lt or -ge like option. |
Need help...in awk ??
I am very glad to see your reply, How could we go for a comparison of one date with other is there any function available in AWK which could do the job.
|
Having thought about this some more ... what are your chances of
changing the date format in the log file? It looks like it's out of a custom app .... your life would be so much easier if you just had the months in a 01..12 notation as well. Imagine 0108 (Jan 8th) to 0203 {Feb 3rd) Code:
awk '{if($1 >= 108 && $1 < 204({print}}' sample.log you could resort to something like this: Code:
awk '/Jan/,/Feb/{if($1 == "Jan" && $2 >= 08){print};if($1 == "Feb" && $2 < 3){print}}' sample.log from Jan to Mar, and the comparison sstring you'd have to build would become increasingly complicated ... Code:
awk '/Jan/,/Mar/{if(($1 == "Jan" && $2 >= 08)||$1="Feb"){print};if($1 == "Mar" && $2 < 3){print}}' sample.log |
Data range using AWK
Hello guru...
i have a log file of this format. i need the out put from specific date range having errors . That date range is the input variables so how could i achieve .Sample log and the codes. $cat sample_txt.log Jan 17 15:39:03 [error] LocalDirectory listFiles(): listing files from dir Jan 17 15:39:03 [error] fm_log:_f_Push() _w_fm_log_export_ftph(): Files f Jan 17 05:58:35 [debug] fm_log_autoexport 1 Jan 18 05:58:35 [debug] fm_log_autoexport 2/var/www/html/sites/default/mods/_ Jan 18 05:58:36 [error] Channel getIntByNode(): getting _chan from Jan 18 05:58:36 [debug] fm_log:_f_Push() Array Jan 18 05:58:36 [notice]fm_log:_f_Push() _w_fm_log_export_active_ftppush__c Jan 18 05:58:36 [error] LocalDirectory isDirectory(): directory '/opt/_d_/ Feb 23 14:32:01 [debug] fm_log_mod Inside log_nodeapi me.. Feb 23 14:32:02 [error] fm_log_mod Inside log_nodeapi me.. Feb 23 14:32:02 [debug] fm_log_mod Inside log_nodeapi me.. Feb 25 13:54:32 [debug] fm_log_mod Inside log_nodeapi me.. Feb 25 13:54:32 [error] fm_log_mod Inside log_nodeapi me.. Feb 25 13:22:44 [notice]fm_log_mod Inside log_nodeapi me.. Feb 25 14:22:34 [error] fm_log_mod Inside log_nodeapi me.. Feb 27 13:22:44 [debug] fm_log_mod Inside log_nodeapi me.. . .. Feb 28 13:22:44 [debug] fm_log_mod Inside log_nodeapi me.. $cat log_check.sh #!/bin/sh echo -e " Please provide the log file" read in_file echo -e " Plese give start date\n" read st_dt echo -e " Please give End date \n" read en_dt awk "/$st_dt/" ' { f=1; } "/$en_dt/" {c=1; } c&&! "/$en_dt/" { c=0;f=0; } (f||c) && /error/ { Arr[$1" "$2]++ } END { for (i in Arr) print i" "Arr[i]" error"; }'"$in_file" In log_check.sh if u replace $dt_dt & $st_dt by some date mean Jan 18 & Feb 25 then it is giving correct answer. awk '/Jan 18/ { f=1; } /Feb 25/ {c=1; } c&&!/Feb 05/ { c=0;f=0; } (f||c) && /rror/ { Arr[$1" "$2]++ } END { for (i in Arr) print i" "Arr[i]" error"; }' file So it is not possible to change the code each time how could i do this with variable substitution in awk , i had gone awk -v for variable substitution but finding difficulties, Need your suggestion . |
Quote:
Have you tried splitting the $st_dt and en_dt into different variables, then combining them? You may also have a problem with the input variable having a space in it. |
I don't understand exactly what you want to do. Do you want to extract the lines with '[error]' or what?
|
All times are GMT -5. The time now is 07:22 AM. |