Help with find command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Help with find command

UNIX for Dummies Questions & Answers


Tags
files, find

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-06-2013
javedkalam javedkalam is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 19 September 2013, 7:41 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 02-06-2013
franzpizzo's Avatar
franzpizzo franzpizzo is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 6 February 2014, 9:56 AM EST
Posts: 68
Thanks: 0
Thanked 12 Times in 12 Posts
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  
Old 02-08-2013
javedkalam javedkalam is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 19 September 2013, 7:41 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot franzpizzo !!
    #4  
Old 02-08-2013
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by franzpizzo View Post
It seems a little twisted, but it works
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 08:39 PM.