Need script to move files based on month


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need script to move files based on month
# 1  
Old 05-04-2015
Need script to move files based on month

Hi ,

I need a script which moves files based on month. Example :

Code:
Apr 29 03:16 log4.txt
Apr 29 03:16 log5.txt

May  4 09:17 log1.txt
May  4 09:17 log2.txt


Move Apr files into Apr2015(Folder)
Move May files into May2015(Folder).

This is urgent requirement , if you can help me that would be great.

Thanks

Last edited by Scrutinizer; 05-04-2015 at 01:56 PM.. Reason: CODE tags
# 2  
Old 05-04-2015
Any attempts from your side?
# 3  
Old 05-04-2015
I'm using below script , but it will move files based on today date:

Code:
#!/bin/bash

MONTH="$(date +'%d''%b''%Y')"

FILES="$(date +'%d''%m''%Y')"

mkdir "${MONTH}"

mv ${FILES}_*.xls ${MONTH}

But I need it to be moved to Folder with a Month(Apr2015).

Last edited by Scrutinizer; 05-04-2015 at 01:56 PM.. Reason: CODE tags
# 4  
Old 05-04-2015
Try - presumed the folder exist - :
Code:
for i in *.txt; do echo mv "$i" ./${i:0:3}2015/; done

Remove the echo if happy...
# 5  
Old 05-04-2015
The year should be generic (It should be incremental). Can you please put in a script and give it to me.
# 6  
Old 05-04-2015
No. I leave this up to you as an exercise.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files with a certain suffix based on how many files are in another folder

Hello, First time poster. I am looking for a way to script or program the process of moving files from one folder to another, automatically, based on the count of files in the destination folder. I was thinking a shell script would work, but am open to the suggestions of the experts... (6 Replies)
Discussion started by: comtech
6 Replies

2. Shell Programming and Scripting

Fetch files based on month

Hi All I have a requirement like below.I have always 12 files got generated in my directory called /xx/out/ abc_2014_10_121.xml abc_2014_09_345.xml abc_2014_08_432.xml abc_2014_07_123.xml abc_2014_06_098.xml abc_2014_05_569.xml abc_2014_04_430.xml abc_2014_03_235.xml abc_2014_02_056.xml... (9 Replies)
Discussion started by: chigurupati.dwh
9 Replies

3. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

4. Shell Programming and Scripting

Moving log files based on month - help with ksh shell script

Hello, I'm trying to move the log files from the parent directory to respective monthly folder and I would be running this script on a weekly basis through cron. I'm new to this scripting and here is what i could come up and it runs without really doing anything. I even tried placing echo... (2 Replies)
Discussion started by: jusblues
2 Replies

5. Shell Programming and Scripting

Need script to move files based on name

Hi folks, I'm new here and appreciate greatly any help. I have a bunch of files that need be moved and renamed. Fortunately, they are all in sequence... Present filename and path: /.catalog1/t76038_842-01 Move to: /.catalog1/76038-01 So, we need to drop the... (8 Replies)
Discussion started by: axslinger
8 Replies

6. Shell Programming and Scripting

Unix Script To Move Files Based On Grep

I am looking for advice on how to write a script that will rename and/or move files to a different directory based upon the results of a grep. Let's say I have ten files in a directory. Some of them - not all - contain the text 'HELLO'. I would like to be able to grep the files for that text,... (3 Replies)
Discussion started by: rjhjr64
3 Replies

7. Shell Programming and Scripting

Script to move files based on Pattern don't work

Hi people, i need you help on this if you can. I have a script that does the move command when it searches for a that doesn't match the pattern. This Pattern is on a list. When it run's and doesn´t found no files but it haves 2 more folders it moves the folders too. Ex:... (1 Reply)
Discussion started by: osramos
1 Replies

8. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

9. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

10. Shell Programming and Scripting

How do you move lines of numbers based on the month

How do you move lines of numbers i.e.(131, 134, 116, etc...) based on the month? Say for instance I only wanted June numbers and not July. This is what the file looks like so far but it runs everyday in a cron job so it will build to July. #cat backupcount.log 131 ,Thu Jun 05 08:00:41 2008... (11 Replies)
Discussion started by: terryporter51
11 Replies
Login or Register to Ask a Question