|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with find command
Hi, Im a newbie.All your suggestions needed. Im developing a script that should that find dat files based on the file name(file name is created has date info) after comparing it with the current timestamp.Let me put it in a clear way. For instance, Say I have files say like Code:
AA_XX_20121208 /*date part in name of the file*/ AA_XX_20121207 AA_XX_20121206 AA_XX_20121205 AA_XX_20121204 AA_XX_20121203 AA_XX_20130108 AA_XX_20130107 AA_XX_20130106 AA_XX_20130105 AA_XX_20130104 AA_XX_20130103 AA_XX_20130208 AA_XX_20130207 AA_XX_20130206 AA_XX_20130205 AA_XX_20130204 AA_XX_20130203 . . .so onFor e.g. this month is February, the script must find all files relating to January and December.Similarly during month of March, i must fetch files of January and February. This has to happen each month . Please note,i do not want to find files based on the modified timestamp (find . -name 'AA_XX_*' -mtime -60) ,but using the name of the file which has date part. Thanks in advance, MJK |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
It seems a little twisted, but it works: Code:
YEAR=`date +%Y` MONTH=`date +%m` MONTH1=$(( MONTH - 1 )) YEAR1=$YEAR if [[ $MONTH1 -eq 0 ]] then MONTH1=12 YEAR1=$(( YEAR - 1 )) fi MONTH2=$(( MONTH1 - 1 )) YEAR2=$YEAR1 if [[ $MONTH2 -eq 0 ]] then MONTH2=12 YEAR2=$(( YEAR1 - 1 )) fi PATTERN1=`printf "AA_XX_%s%02d" $YEAR1 $MONTH1` PATTERN2=`printf "AA_XX_%s%02d" $YEAR2 $MONTH2` find . -name $PATTERN1\* find . -name $PATTERN2\* |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks a lot franzpizzo !!
|
|
#4
|
|||
|
|||
|
Another sh-based alternative: Code:
read m y <<EOF $(date +'%m %Y') EOF read m1 y1 m2 y2 <<EOF $(((m-1+11)%12+1)) $([ $m -eq 1 ] && y=$((y-1)); echo $y) \ $(((m-1+10)%12+1)) $([ $m -lt 3 ] && y=$((y-1)); echo $y) EOF # m1/y1 is the month/year of one month ago # m2/y2 is the month/year of two months ago. Regards, Alister Last edited by alister; 02-08-2013 at 01:21 PM.. |
| Sponsored Links | ||
|
![]() |
| Tags |
| files, find |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to use grep & find command to find references to a particular file | Gangam | Shell Programming and Scripting | 2 | 09-22-2011 03:52 AM |
| Simplified find command to find multiple file types | vickramshetty | Linux | 2 | 05-28-2010 01:28 PM |
| how to find a file named vijay in a directory using find command | amirthraj_12 | UNIX for Dummies Questions & Answers | 6 | 10-25-2008 12:37 PM |
| Little bit weired : Find files in UNIX w/o using find or where command | jatin.jain | Shell Programming and Scripting | 10 | 09-19-2007 06:47 AM |
| command find returned bash: /usr/bin/find: Argument list too long | yacsil | Shell Programming and Scripting | 1 | 12-15-2003 05:38 PM |
|
|