Sponsored Content
Full Discussion: grep with date
Top Forums Shell Programming and Scripting grep with date Post 302580810 by methyl on Friday 9th of December 2011 05:37:59 PM
Old 12-09-2011
The "ctime" timestamp is rarely of any use. Some backup software changes it after backing up files. It also changes if you change the permissions of the file.
Stick to "mtime" for this purpose.

In your original post, the issue is in this command:
Quote:
grep 'date "+%b %d"'
Anything between single quotes ' ' is just a fixed string. You probably intended to type backticks ` ` to ask the Shell to execute the command. However the $( command ) syntax is preferred nowadays.
Also the "date" command included the parameter "%d" which gives the day of the month with a leading zero. This would not match a "ls -la" display until tomorrow (the 10th). The parameter "%e" is the day of the month with a space fill when it is a single digit - perfect for matching "ls -la" format.


CarloM's answer is good and corrects the original bugs in your script.

For large directories there are more sophisticated (and faster) methods using "find".
This User Gave Thanks to methyl For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ls -l | grep $date (failing)

Example file list > ls -l -rwxr-xr-x 1 ....... ...... 1707 Feb 5 2004 file1 -rwxr-xr-x 1 ....... ...... 175 Jan 21 2005 file2 -rwxr-xr-x 1 ....... ...... 95 Apr 1 16:15 file3 The Script #!/bin/ksh # date variables start_date_Y=`date +%Y` # year (ie:... (1 Reply)
Discussion started by: yongho
1 Replies

2. Shell Programming and Scripting

grep for date in file

Hi, i have a script that stores the date in a variable as follows: DATESTAMP=`date +"%m%d%Y"` I also have another file called HOLIDAYFILE which stores all of our holidays as follows: 01/01/2007 07/04/2007 What i need to do is use the grep statement in my script to see if DATESTAMP... (2 Replies)
Discussion started by: scabral
2 Replies

3. Shell Programming and Scripting

grep using date format

i have a process ruuning root 843786 835648 0 Nov 10 - 0:31 java root 860340 1 0 Nov 11 - 0:31 then how to grep this using date above i have written a script ---------------------------- #!/bin/ksh a=`date +"%m-%d"` ps | grep root | grep "$a" >> file1... (8 Replies)
Discussion started by: ali560045
8 Replies

4. Shell Programming and Scripting

grep time and date

Hi, I have a file which is a result of a script running every two minutes. What I wanted to do is to grep a specific date and time (hour and minute) from the file and then count the occurance of 201. I need to get the result of occurance of 201 every 5 minutes. What should I include in my... (8 Replies)
Discussion started by: ayhanne
8 Replies

5. Shell Programming and Scripting

Grep date from ls -l

I have a script which required the month and day as the input ex : ./script <Month> <date> from this I get the list of files to do further logics. The problem is when I assign these $1 and $2 to variables, and use grep command in the script ls -l |grep "$1 $2" it works fine for two... (1 Reply)
Discussion started by: GenMen
1 Replies

6. Shell Programming and Scripting

grep tomorrow's date

Hi guys, I need to find tomorrows date in date fomat and should be in variable. as I need to grep this date in a flat file ie. if today's date is '09 JAN 2009' output should be '10 JAN 2009' unix/perl script will be fine. (21 Replies)
Discussion started by: ssachins
21 Replies

7. Shell Programming and Scripting

grep based on date

Hello! I have a circular log file which contains data that looks like this: 01/23/09 08:24:19:04 treadle_data = L3^M 01/23/09 08:24:19:09 STRIP 3 LOW 01/23/09 08:24:19:09 treadle_data = L4^M 01/23/09 08:24:19:09 STRIP 4 LOW 01/23/09 08:24:19:09 treadle_data = FF^M 01/23/09 08:24:19:09... (8 Replies)
Discussion started by: sdilucca
8 Replies

8. Shell Programming and Scripting

grep problem with date

Hi, can you correct the below syntax for me? echo `grep "Issue" new`date +'%y%m%d'`.csv` I am not able to execute above. PS: "Issue" is a keyword I am seraching in a new<date>.csv I am going to use above in i statement as below: if then do this else do that (2 Replies)
Discussion started by: amit.mathur08
2 Replies

9. Shell Programming and Scripting

Calculating expiry date using date,sed,grep

Hi, I would greatly appreciate it if someone can help me with my problem. I have a crawler which collects spam URLs everyday & this data needs to be published in a blacklist. Here's the catch: The "Time To Live" (TTL) for each URL is 3 months (or whatever for that matter). If i see the... (5 Replies)
Discussion started by: r4v3n
5 Replies

10. UNIX for Dummies Questions & Answers

Grep using date issue

I'm using the below to grep two strings from my log file. grep "09:49.*yellow" out.logNow, i wish to search for all times within 3 minutes of the greped time i.e All time starting from 09:49:00 to 09:51:00. Currently it searches only for 09:49:* and also searches incorrect entry like... (14 Replies)
Discussion started by: mohtashims
14 Replies
Time::CTime(3)						User Contributed Perl Documentation					    Time::CTime(3)

NAME
Time::CTime -- format times ala POSIX asctime SYNOPSIS
use Time::CTime print ctime(time); print asctime(localtime(time)); print strftime(template, localtime(time)); strftime conversions %% PERCENT %a day of the week abbr %A day of the week %b month abbr %B month %c ctime format: Sat Nov 19 21:05:57 1994 %d DD %D MM/DD/YY %e numeric day of the month %f floating point seconds (milliseconds): .314 %F floating point seconds (microseconds): .314159 %h month abbr %H hour, 24 hour clock, leading 0's) %I hour, 12 hour clock, leading 0's) %j day of the year %k hour %l hour, 12 hour clock %m month number, starting with 1 %M minute, leading 0's %n NEWLINE %o ornate day of month -- "1st", "2nd", "25th", etc. %p AM or PM %r time format: 09:05:57 PM %R time format: 21:05 %S seconds, leading 0's %t TAB %T time format: 21:05:57 %U week number, Sunday as first day of week %w day of the week, numerically, Sunday == 0 %W week number, Monday as first day of week %x date format: 11/19/94 %X time format: 21:05:57 %y year (2 digits) %Y year (4 digits) %Z timezone in ascii. eg: PST DESCRIPTION
This module provides routines to format dates. They correspond to the libc routines. &strftime() supports a pretty good set of coversions -- more than most C libraries. strftime supports a pretty good set of conversions. The POSIX module has very similar functionality. You should consider using it instead if you do not have allergic reactions to system libraries. GENESIS
Written by David Muir Sharnoff <muir@idiom.com>. The starting point for this package was a posting by Paul Foley <paul@ascent.com> LICENSE
Copyright (C) 1996-1999 David Muir Sharnoff. License hereby granted for anyone to use, modify or redistribute this module at their own risk. Please feed useful changes back to muir@idiom.com. perl v5.12.1 2004-02-08 Time::CTime(3)
All times are GMT -4. The time now is 09:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy