Script for creating a directory & move the .tif files in it.


 
Thread Tools Search this Thread
Top Forums Programming Script for creating a directory & move the .tif files in it.
# 1  
Old 04-25-2012
Script for creating a directory & move the .tif files in it.

Hi Team,

I have thousands of TIF files which are converted from PDF. Below is a sample of it.

LH9406_BLANCARAMOS_2012041812103210320001.tif
LH9406_BLANCARAMOS_2012041812103210320002.tif
LH9406_BLANCARAMOS_2012041812103210320003.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250001.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250002.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250003.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250004.tif
LH9411_ANGENIAHUTCHINSON_2012041812102510250005.tif
LH9412_DANIELMATEO_2012041812102310230001.tif
LH9412_DANIELMATEO_2012041812102310230002.tif
LH9414_MICHAELLEWIS_2012041812102010200001.tif
LH9414_MICHAELLEWIS_2012041812102010200002.tif
LH9414_MICHAELLEWIS_2012041812102010200003.tif
LH9414_MICHAELLEWIS_2012041812102010200004.tif

I want to create folders like LHR-001,LHR002,LHR-003.....& w ant to move approximately 50 to 60 images in one folder in such a way that all images of first part of file name should be in one folder.

eg. If first 50 files moves in LHR-001 folder & 50th file is
LH9411_ANGENIAHUTCHINSON_2012041812102510250003.tif then it should move the remaining 2 files (LH9411_...004.tif & LH9411_...005.tif) also in LHR-001. Means count of that folder is 52 & afterwards it goes further to move files in LHR-002.


I have a script which create a folder & moves 50 files in it but that script moves exact 50 files. The problem is, if i run that script the sometimes images from single PDF are split in two folders. Here is my script sample....

cc=50; c=0; folder=1; for i in *; do c=`expr $c + 1`; let "r = $c % $cc" ; if [ $r -eq 0 ] ; then folder=`expr $folder + 1` ; fi ; if [ ! -d $folder ]; then mkdir $folder; fi ; mv "$i" $folder/ ;done

Please help me out.

Thank You.
# 2  
Old 04-25-2012
What Operating System and version do you have and what Shell are you using.

Does your script actually work? It looks like it creates folders called 1 , 2 , 3 etc. . The second and subsequent time the script is run it will go very wrong because it will try redistributing the directories created on the previous run.

How many files are there exactly?
Is there any possibility of exceeding LHR-999 ?

If you are still at design stage, I would avoid having hyphen characters in filenames.

Last edited by methyl; 04-25-2012 at 08:11 PM.. Reason: typos
# 3  
Old 04-25-2012
I am working on ubuntu 2.6.20-17-server

Yes my script is working. You are right it creates folders like 1,2,3,4.....

I can't say the exact count for files. Because daily count is different, but there is no possibility of exceeding LHR-999. Maximum it will go upto 500 folders.
# 4  
Old 04-25-2012
Quote:
I can't say the exact count for files. Because daily count is different
In that case I sign off now and recommend that other posters take note.
# 5  
Old 04-27-2012
Why??????????? Smilie
# 6  
Old 04-28-2012
Quote:
Originally Posted by paragnehete
I want to create folders like LHR-001,LHR002,LHR-003.....& w ant to move approximately 50 to 60 images in one folder in such a way that all images of first part of file name should be in one folder.

eg. If first 50 files moves in LHR-001 folder & 50th file is
LH9411_ANGENIAHUTCHINSON_2012041812102510250003.tif then it should move the remaining 2 files (LH9411_...004.tif & LH9411_...005.tif) also in LHR-001. Means count of that folder is 52 & afterwards it goes further to move files in LHR-002.
So is LHR-001 only LH9411_ files? or do we unconditionally copy 50 and then finish the current prefix?
# 7  
Old 04-30-2012
It should unconditionally moves 50+ files & then finish the current prefix.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need BASH Script Help to Move Files While Creating Directories

I've got this script to loop through all folders and move files that are more than 2 years old. I'm using the install command because it creates the necessary directories on the destination path and then I remove the source. I'd like to change the script to use the mv command since it is much... (4 Replies)
Discussion started by: consultant
4 Replies

2. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. UNIX for Dummies Questions & Answers

Move Directory & Contents Between Two Machines

Hi All, I have a large amount of files that I need to copy from one server to another server using SFTP. Can comeone please help me with the command I would use here? Here is what I am thinking, but being new at this I know this is probably wrong: Login to the destination host using... (1 Reply)
Discussion started by: SalientAnimal
1 Replies

5. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

6. Linux

Create folder by script & move files in it

Hi Team, I have over 1 lakh pdf files. I want to create folders like Disk-1, Disk-2 ..... & want to move 3000 pdfs per folder. Can i do it by script? Please help me. Thanks & Regards Parag Nehete (4 Replies)
Discussion started by: paragnehete
4 Replies

7. Shell Programming and Scripting

Script to move files to a directory according to date

hi all, here is the description to my problem. input parameter: $date1 based on the date i need to select three files starting with audit.log* based on its modified date, a date before, a date after(if its exists). We need to compare the input date to modified date of the file. And then... (3 Replies)
Discussion started by: ashrocks
3 Replies

8. Shell Programming and Scripting

Script That Can navigate to 3 differents directory & remove files under them

Hi I am Trying to Write a script that can goto 4 different directorys on the server & remove the Files older then 30 days ?? /logs logs1 logs2 logs3 Now I need to remove files under logs1 logs2 logs3 which are older then 30 days whose name stat 'sit' , 'mig','bld' . in... (3 Replies)
Discussion started by: Beginner123
3 Replies

9. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

10. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies
Login or Register to Ask a Question