awk statement to find events from a specific date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk statement to find events from a specific date
# 1  
Old 06-25-2010
awk statement to find events from a specific date

I have a script which archives log file events which are 90-days old. Script works fine but I wanted some input on one aspect of this script. My nawk statement, bolded below, that removes events 90-days prior from today, I need it to find anything 90-days or older. The log file date pattern looks like this 03-29-2010
Code:
#!/bin/sh
LOG=tool.log
# Script will compress and archive tool log files older than 90-days
# Perl script to identify the date 90 days prior from today
  date=`perl <<'EOF'
  @T=localtime(time-86400 * 89);printf("%02d-%02d-%02d\n",$T[4]+1,$T[3],$T[5]+1900);
  EOF`
# Next statement will add logs 90-days old in command_archive.gz file
  nawk 'BEGIN {FS="\n"}{RS="#"}{ORS="#"}{if ($2 ~ /^'$date'/) print $0;}' $LOG > archive.temp
  gzip -c archive.temp >> command_archive.gz
# Next statement will remove logs 90-days old from the tool.log file
  nawk 'BEGIN {FS="\n"}{RS="#"}{ORS="#"}{if ($2 !~ /^'$date'/) print $0;}' $LOG > tmp_tool.log
  cp tmp_tool.log $LOG

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

2. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

3. UNIX for Dummies Questions & Answers

Find Commands Run on Specific Date

Hello All, I was wondering if anyone knew of a way to find out what commands were run on a specific date. I'm looking to see if I can find certain commands that were run on 3/4, today is 3/10...? Any thoughts or ideas would be much appreciated! Thanks in Advance, Matt ----------... (3 Replies)
Discussion started by: mrm5102
3 Replies

4. Shell Programming and Scripting

Find files for a specific date

Hi, I am looking to find files of a specific date. I am on Sun Solaris so newermt doesnot work.. I thought of using mtime but not getting how to use it. Please help me with this.. Regards Abhinav (3 Replies)
Discussion started by: abhi1988sri
3 Replies

5. Shell Programming and Scripting

Find files with specific date

Dear all, kindly i have some files with different dates i need to grep word from these files but i need to search in files with date 2012-12-02 not all files in this directory do u have any command (4 Replies)
Discussion started by: maxim42
4 Replies

6. Shell Programming and Scripting

Find and print specific date with awk

hi all I would like to help me find the problem with this script to find and print to the screen a specific date of a log file that I have on my server, the date it is received as the first argument in the script $ 1 Here I show you a few lines that made ​​the idea of ​​my log file: ****... (4 Replies)
Discussion started by: gilmore666
4 Replies

7. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

8. Shell Programming and Scripting

help with awk statement and date formatting

I am trying to write a script that will execute one awk statement if the day is Monday and another awk statement for any other day of the week. below is my code. I keep getting "invalid date". I know this is something simple but i can't determine exactly what it is. Please help. if then ... (2 Replies)
Discussion started by: bds052189
2 Replies

9. Shell Programming and Scripting

Getting a specific date from cal output with AWK

Hi guys! I'll make this short... Is there any good way to get the day number that first matches the Monday column from the cal command output with awk (or any other text manipulator commands) ? I'm sorry if my question wasn't clear at all. For example... One cal output would be $... (6 Replies)
Discussion started by: Casey
6 Replies

10. AIX

find files with specific date and time

Hi, I wanna to find files with specific date and time. I know this command: ls -ltr /system1/*.505 | grep 'Jan 18 09:00'. I want the 'Jan 18 09:00' not hard coded, I want it coming from the system date and time. And I want the time varies from 09:00-09:05. Is this possible without heavy... (3 Replies)
Discussion started by: itik
3 Replies
Login or Register to Ask a Question
update(n)						       Tcl Built-In Commands							 update(n)

__________________________________________________________________________________________________________________________________________________

NAME
update - Process pending events and idle callbacks SYNOPSIS
update ?idletasks? _________________________________________________________________ DESCRIPTION
This command is used to bring the application ``up to date'' by entering the event loop repeatedly until all pending events (including idle callbacks) have been processed. If the idletasks keyword is specified as an argument to the command, then no new events or errors are processed; only idle callbacks are invoked. This causes operations that are normally deferred, such as display updates and window layout calculations, to be performed imme- diately. The update idletasks command is useful in scripts where changes have been made to the application's state and you want those changes to appear on the display immediately, rather than waiting for the script to complete. Most display updates are performed as idle callbacks, so update idletasks will cause them to run. However, there are some kinds of updates that only happen in response to events, such as those triggered by window size changes; these updates will not occur in update idletasks. The update command with no options is useful in scripts where you are performing a long-running computation but you still want the applica- tion to respond to events such as user interactions; if you occasionally call update then user input will be processed during the next call to update. SEE ALSO
after(n), bgerror(n) KEYWORDS
event, flush, handler, idle, update Tcl 7.5 update(n)