Sponsored Content
Full Discussion: ls -l | grep $date (failing)
Top Forums Shell Programming and Scripting ls -l | grep $date (failing) Post 79861 by jim mcnamara on Monday 1st of August 2005 03:30:49 PM
Old 08-01-2005
file times are a pain in the butt.

try using the script attached below like this:
Code:
# find files from january 01 2005
for file in `ls -1`
do
      filetime.pl $file | grep -q 20050101
      if [ $? -eq 0 ] ; then
             echo "$file"
      fi
done

Code:
#!/usr/bin/perl
# point the above to the locaction of perl on your system
#^ PROGRAM DESCRIPTION
#^ -------------------
#^ This program prints the modification times of files.
#^ It uses the following format:  inodetime.pl filename
#^ It will accept:  inodetime.pl filename1 filename2 filename3
#^                  inodetime.pl /tmp/file*
#^ The format of the output is: YYYYMMDDhhmmss filename
#^ example:
#^           $ filetime.pl /tmp/t*
#^           19961115105425 /tmp/test.sql 
#^           19970116113616 /tmp/tststat.pl 
#^ 

############################################
# Get the (next) input from the command line 
############################################
while ($curfile = $ARGV[0])
{
   #################################################
   # Do following code block only if $curfile exists
   #################################################
   if (-e $curfile)
   {

      # stat structure into variables

      ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
      $atime,$mtime,$ctime,$blksize,$blocks)
      = stat("$curfile");

      # time structure into variables

      local($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
      $yr = ($yr>=70) ? $yr+1900 : $yr+2000;
      $yr="$yr";
      $mon = (++$mon < 10) ? "0$mon" : "$mon";
      $day = ($day < 10) ? "0$day" : "$day";
      $hr  = ($hr < 10) ? "0$hr" : "$hr";
      $min = ($min < 10) ? "0$min" : "$min";
      $sec = ($sec < 10) ? "0$sec" : "$sec";

      # Rearrange in the YYYYMMDDhhmmss format and assign to $dte variable

      $dte = join('',$yr,$mon,$day,$hr,$min,$sec);

      # Print modification date and filename

      print ("$dte\n");
      }

   # Shift to next position in command line
   shift (@ARGV);
}

 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

grep using date format

i have few persistance apps like below pipe 1118370 1200312 0 Dec 18 - 192:03 java - _AppName=DBSyncController pipe 2523376 1568906 0 feb 25 - 386:15 java -Xms128m -Xmx1024m -D_AppName=DBMaint com pipe 7462996 2531452 0 march 18 - 23:22 java... (4 Replies)
Discussion started by: ali560045
4 Replies

3. 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

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

grep with date

I have few files in one directory as below and I require the files that were created today... $ls -ltr -rw-r--r-- 1 abc abc 0 Dec 5 17:34 file4.txt -rw-r--r-- 1 abc abc 0 Dec 5 17:34 file5.txt -rw-r--r-- 1 abc abc 0 Dec 7 17:34 file6.txt -rw-r--r-- 1... (7 Replies)
Discussion started by: giridhar276
7 Replies

8. Shell Programming and Scripting

Grep out only today's date

Hi, I have some log files. I've been asked to grep out error messages that have happened ONLY today. (However, the logs keep messages a long time so they have error messages going back weeks) They log details in these fields (order): Month Day Time Server message I can grep out the... (8 Replies)
Discussion started by: horhif
8 Replies

9. Shell Programming and Scripting

Grep failing on a certain string

Hello, I am trying to issue the following grep statement to no luck: %3Eps"]root@server>ps -ef | grep -v grep | grep received/1 -c grep: can't open -c root@server] if i grep on received/1, it works..but there is received/1/pdf, received/1/txt, received/1/afp ...but they all have... (2 Replies)
Discussion started by: jeffs42885
2 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
shift(1)							   User Commands							  shift(1)

NAME
shift - shell built-in function to traverse either a shell's argument list or a list of field-separated words SYNOPSIS
sh shift [n] csh shift [variable] ksh * shift [n] DESCRIPTION
sh The positional parameters from $n+1 ... are renamed $1 ... . If n is not given, it is assumed to be 1. csh The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for the variable not to be set or to have a null value. ksh The positional parameters from $n+1 $n+1 ... are renamed $1 ..., default n is 1. The parameter n can be any arithmetic expression that evaluates to a non-negative number less than or equal to $#. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 shift(1)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy