Need last month files after 10th of every month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need last month files after 10th of every month
# 1  
Old 07-16-2014
Need last month files after 10th of every month

Hi,
I need all file names in a folder which has date >= 10th of last month,

Example
: files in folder
Code:
AUTO_F1_20140610.TXT
BUTO_F1_20140616.TXT
CUTO_F1_20140603.TXT
FA_AUTO_06012014.TXT
LA_AUTO_06112014.TXT
MA_AUTO_06212014.TXT
ZA_AUTO_06232014.TXT

Output:
Code:
AUTO_F1_20140610.TXT
BUTO_F1_20140616.TXT
LA_AUTO_06112014.TXT
MA_AUTO_06212014.TXT
ZA_AUTO_06232014.TXT


Last edited by Scrutinizer; 07-16-2014 at 06:12 PM.. Reason: code tags
# 2  
Old 07-17-2014
The format of date is not fixed in your files !?
# 3  
Old 07-17-2014
Hello nani1984,
  • What have you tried so far?
  • What errors/output are you getting?
  • What OS and version are you using?
  • What shell or other tools would you prefer to code in?
  • How do you think you can identify the files? (file name embedded date or last update time?)
Most importantly, What have you tried so far?

There are probably many ways to achieve what you want but you need to be clear about what you want and what you have. Showing some effort and therefore the specific thing that you are stuck with is likely to get a better response. Can you help us to help you?

For a given date (tell us which one you are basing it on), please show a sample with ls -l the range of files you are likely to have, showing us which you want to process and which to ignore. It will focus the discussion.

When you are discussion files based on the 10th or later of the month, it would be good to know what differences there will be with running the process before or after 10th. Does it make a difference?

Do you have any concerns over scheduling the work?


Thanks, in advance,
Robin
UK
# 4  
Old 07-17-2014
Hi Robin,

i need to run this process every last day of the month and i need to move all the files which i received on after 10th of that month to the different folder, here i am considering the dae embeded in the file.
For example:
Code:
AUTO_F1_20140610.TXT -- this file , i received on 06/10/2014
LA_AUTO_06112014.TXT -- this file , i received on 06/11/2014


Last edited by Scott; 07-17-2014 at 04:36 PM.. Reason: Code tags
# 5  
Old 07-17-2014
Please consider answering the other questions to give us the best opportunity to help you.

Please wrap code and data input/output in CODE tags, like this:-
Quote:
[CODE]This is my code[/CODE]
to produce the following (fixed character width, space respected):-
Code:
This is my code

It makes it far easier to read. It was adjusted for you by Scrutinizer this time. Having file names of different format will make it a little more awkward, but not insurmountable.

Considering ? to be a single character and * to be zero or more, are your files all of two formats, ?UTO_*_YYYYMMDD and ??_?UTO_DDMMYYYY? That's simple enough to work on, but clarity would be useful.

Have I guessed the date format correctly even? I'm assuming that we have either most significant to least (Year, Month, Day) or least significant to most (Day, Month, Year) If you have the Day in the middle, we need to know. It's not clear from your text as you just give us:-
Quote:
AUTO_F1_20140610.TXT -- this file , i received on 06/10/2014
LA_AUTO_06112014.TXT -- this file , i received on 06/11/2014
.... which to a British reader (and many others) is 6th October 2014 and 6th November 2014 respectively. They are both in the future for now, but you could be running your clocks forward for some reason so we need to check.




Regards,
Robin
# 6  
Old 07-17-2014
Sorry for not mentioning,
Code:
AUTO_F1_20140610.TXT -- this file , i received on 06/10/2014---June/10/2014
LA_AUTO_06112014.TXT -- this file , i received on 06/11/2014---June/11/2014

so i received the above files on 10 & 11th of June.
we can receive files in any format , either YYYYMMDD or DDMMYYYY.

I tried to extract the dates in the files using below CODE
Code:
 ls -1 *.TXT|awk 'BEGIN{FS="[_.]"}{print $(NF-1)}'

It gives just dates like this "20140610" , i got all the dates, but stuck there to move forward "to move all the files which we received after 10 of the month" .

Please let me know if any questions.

Last edited by Scott; 07-17-2014 at 04:37 PM.. Reason: Code tags
# 7  
Old 07-17-2014
Tossed this together. Should give you a base to start.

Code:
#!/bin/bash
#

# check command-line for correct usage
if [ $# -ne 2 ]; then
    echo "Usage: ${0##*/} </path/to/directory> <four-digit year>"
    exit 1
fi

# store the given path
pth=$1

# store the year
year=$2

# loop through the given directory
# check the index where 2014
for files in ${pth}/*; do
    chkIndex=$(echo ${files##*/} | grep -bo $year | cut -d: -f1)
    if [ "$chkIndex" -ge 12 ]; then
        day=$(echo ${files##*/} | cut -c 11-12)
    else
        day=$(echo ${files##*/} | cut -c 15-16)
    fi
    if [ $day -ge 10 ]; then
        echo $files
    fi
done

# done
exit 0

./fileLst.sh /tmp/testdir 2014
/tmp/testdir/AUTO_F1_20140610.TXT
/tmp/testdir/BUTO_F1_20140616.TXT
/tmp/testdir/LA_AUTO_06112014.TXT
/tmp/testdir/MA_AUTO_06212014.TXT
/tmp/testdir/ZA_AUTO_06232014.TXT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Get last month files

Hi All, How to get last month files. Ex : 1st Jan i have to get Dec 31 days files and on Feb 1st i have to get Jan 31 days files and on Mar 1st i have to get Feb 28 days files. Below are the example files with date and timestamp. aaa.txt.timestamp aaa.txt.timestamp aaa.txt.timestamp Please... (7 Replies)
Discussion started by: kiranparsha
7 Replies

2. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

3. Shell Programming and Scripting

Convert From Month Number to Month Name

Hi, I have a script that accepts an input date from the user in yyyy-mm-dd format. I need to get the mm-dd part and convert it to month name. example: 2011-11-15 I want that to become "Nov 15" I don't have the GNU date, I am using an AIX os. Thanks. (1 Reply)
Discussion started by: erin00
1 Replies

4. HP-UX

Removing files from a particular month

Hi All I am trying to remove files from february, only using the following commands: find . -mtime 70 -exec rm {} \;, but I dont seem to get them deleted. But I am confused, now, because I have been told to use -atime, like find . -atime 75 -exec rm {} \;Please can you help! FR (8 Replies)
Discussion started by: fretagi
8 Replies

5. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

6. Shell Programming and Scripting

How to delete1 month old files?

Hi, I need to create a script which should delete all the log files which are 1 month old or older than that. For ex: Today's date -- > 09/30/2010 Directory --> /user/work/log/ Files--> log.07182010 created on 07/18/2010 log.08182010 created on 08/18/2010 log.09182010 ... (4 Replies)
Discussion started by: ustechie
4 Replies

7. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

8. HP-UX

deleting files for a particular month

Hi, I want to delete files of a particular month in a particular directory. Please tell me a script for this so that it will search a particular kind of file in that directory and delete them.I am using HP-UX. (1 Reply)
Discussion started by: adityam
1 Replies

9. Shell Programming and Scripting

How to get previous month files

Hi, My task to to delete files which are of previous months. I have files named as follows *CCYYMMDD.xls. on a particular day i have delete previous months files i.e in Dec i have delete all nov files which look like 200511DD.XLS in Jan i have to delete all Dec files 200512DD.xls ... (7 Replies)
Discussion started by: savitha
7 Replies

10. Shell Programming and Scripting

Find all files by month

Hi, I am trying to do achieving of files by months. find /test -name \*.* -mtime +30 will give me the result of all modified files after 30 days. But lets say i want to list all files that is modified in last months... what is the command to do it? Thanks! (13 Replies)
Discussion started by: maldini
13 Replies
Login or Register to Ask a Question