![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep date from ls -l | GenMen | Shell Programming and Scripting | 1 | 05-01-2008 09:53 PM |
| grep time and date | ayhanne | Shell Programming and Scripting | 8 | 01-06-2008 09:12 AM |
| grep using date format | ali560045 | Shell Programming and Scripting | 4 | 12-26-2007 08:59 AM |
| grep using date format | ali560045 | Shell Programming and Scripting | 8 | 12-11-2007 06:39 PM |
| grep for date in file | scabral | Shell Programming and Scripting | 2 | 05-29-2007 12:27 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
ls -l | grep $date (failing)
Example file list
Code:
> 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 Code:
#!/bin/ksh
# date variables
start_date_Y=`date +%Y` # year (ie: 1998, 2005)
start_date_b=`date +%b` # month (ie: Jun, Jul)
start_date_d=`date +%d` # day (ie: 09, 25)
# format the date value for day for `ls -al | grep <date>`
# ex: converts day value of '01' into ' 1' or '09' to ' 9', etc)
typeset -L1 get_first_char # used to get first character of `date +%d`
typeset -R1 get_second_char # used to get second character of `date +%d`
get_first_char="$date_d"
get_second_char="$date_d"
if (( get_first_char==0 )); then
date_d=" ${get_second_char}"
fi
ls -l | grep "$date_b $date_d"
Can anyone suggest the workaround for this? Last edited by yongho; 08-01-2005 at 11:54 AM.. |
|
||||
|
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);
}
|
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|