Sponsored Content
Top Forums Shell Programming and Scripting Sort/move files into folders and rename existing files. Post 303045360 by oatfoolery on Wednesday 18th of March 2020 06:29:47 AM
Old 03-18-2020
Sort/move files into folders and rename existing files.

Hello everyone!
Im having a few problems with my file moving script.
Im trying to move files into folders based on the filenames and if a file already exists rename that file.

The files consists of three sets of different filenames. They will be moved/sorted into the folder structure below. The Source and Destination path will always be static.
Code:
OBJECTS/2018/1803/180313/DNG
OBJECTS/2018/1803/180313/TIFF
OBJECTS/2018/1803/180313/JPEG

Example filenames:

Code:
15512-1.dng
15512-1.tif
15512-1.jpg

180313-1.dng
180313-1.tif
180313-1.jpg

2002005-1.dng
2002005-1.tif
2002005-1.jpg


The code below kind of works but there must be a better way to loop through the files than to use two “While do”ť statements.
Another thing I'm having trouble with is if a file already exists, I would like to rename or append something to that existing file. I tried with --backup but all I get is illegal option, most likely due to me testing this on MacOS.

My intension is to run this on my Synology server as an automated task every evening.
When i try to execute the script on the server it complains about the Source path, maybe not correctly formatted?
find: `"/volume1/Archive/IMAGES/UPLOAD/TIFF/"': No such file or directory

Code:
#!/bin/bash
SRC1=/volume1/Archive/IMAGES/UPLOAD/JPEG/
SRC2=/volume1/Archive/IMAGES/UPLOAD/TIFF/
DST=/volume1/Archive/IMAGES/OBJECTS/
{
export LC_CTYPE=UTF-8
while IFS= read -r -d $'\\0' f1
do
    n=${f1##*/}
    [[ $n =~ ^(([0-9]{2})([0-9]{1,2})[0-9]{2,3})[^0-9] ]] || continue	 #5,6 & 7-digits (yymkk) (yymmkk) (yymmkkk)
    p=${BASH_REMATCH[1]}
    y=${BASH_REMATCH[2]}
    m=${BASH_REMATCH[3]}
    m='0'$m
    m=${m: -2}
	
	jpg=${DST}/'20'${y}/${y}${m}/${p}/JPEG
	[[ -d $jpg ]] || mkdir -p \"$jpg\" || continue
    

	cp -v -n \"$f1\" \"$jpg\"
	
	
done < <(find \"$SRC1\" -type f -iname '*.jpg' -print0)

# TIFF files
while IFS= read -r -d $'\\0' f2
do
    n=${f2##*/}
    [[ $n =~ ^(([0-9]{2})([0-9]{1,2})[0-9]{2,3})[^0-9] ]] || continue	 #5,6 & 7-digits (yymkk) (yymmkk) (yymmkkk)
    p=${BASH_REMATCH[1]}
    y=${BASH_REMATCH[2]}
    m=${BASH_REMATCH[3]}
    m='0'$m
    m=${m: -2}
	
	tif=${DST}/'20'${y}/${y}${m}/${p}/TIFF
	[[ -d $tif ]] || mkdir -p \"$tif\" || continue
    
	cp -v -n \"$f2\" \"$tif\"
	
	
done < <(find \"$SRC2\" -type f -iname '*.tif' -print0)


} 2>&1
exit 0


Last edited by oatfoolery; 03-18-2020 at 08:54 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files and rename ??

1. If I have a file-yyyymmdd.dat in a directory DATA1, then how do I move this file to directory DATA2 and the file name change to file-yyyymmdd.dat.currenttime I can manual do this $mv fileA-yyyymmdd.dat ./DATA2/fileA-yyyymmdd.dat.`date +%Y%m%d%H%M%S` but how do I move all of the files in... (1 Reply)
Discussion started by: sabercats
1 Replies

2. UNIX for Dummies Questions & Answers

Using Rename to move files

I am connecting to a remote server (Unix) and doing a ftp dowmload of files. The script (VB script) works fine except for not being able to move the downloaded files on the remote server to another folder. I need to move all files with an .asc extesnion from folder "tovecellio_edi" to folder... (1 Reply)
Discussion started by: snufse
1 Replies

3. UNIX for Dummies Questions & Answers

Move folders containing certain files

Hello, How can I move just the folders that contains files modified n days ago? Source tree: |-- SourceFolder | |-- Subfolder1 | | |-- file1.dat | | `-- file2.dat | |-- Subfolder2 | | |-- filea.dat | | `-- fileb.dat Destination tree: |-- ... (3 Replies)
Discussion started by: xavix
3 Replies

4. Shell Programming and Scripting

Move files to Folders

Hi Friends, Below is my requirement and i am not clear how to approach this issue in unix programming. I have a folder with 2500 files. The files are in below format. 1234_name1.txt 1234_name123.txt 4567_name1.txt 4567_name123.txt and i need a program which will read each file from this... (5 Replies)
Discussion started by: diva_thilak
5 Replies

5. UNIX for Dummies Questions & Answers

Rename files to indexnumber in multiple folders

I have multiple subfolders with multiple jpg I want the group of files in each subfolder renamed to their index number (3 digits) in the folder, so: folder/a.jpg = folder/001.jpg folder/b.jpg = folder/002.jpg folder/c.jpg = folder/003.jpg folder2/1.jpg = folder2/001.jpg folder2/2.jpg =... (2 Replies)
Discussion started by: cmanniche
2 Replies

6. Shell Programming and Scripting

Move all files but not folders to a new folder

Hi, I have a sub directory with a number of files and folders. What i want is a subdirectory with just folders and not files for cleanliness sake. So I want to move the files into the new folder but keep the folders in the same place. Move all files (but not folders) to new folder. I am... (4 Replies)
Discussion started by: Hopper_no1
4 Replies

7. Shell Programming and Scripting

How to move files to existing .tgz file?

Hi, I have already created the tar files. which consist of some log files and Audit.csv plz see the below code for that ================================================ tar -Pczf ARCH/${arc_date}.tgz $LOG/*.log $REYE/CEP/FiAdapter/Audit.${arc_date}.csv ... (3 Replies)
Discussion started by: pspriyanka
3 Replies

8. Shell Programming and Scripting

Moving files to folders and rename

Hello! I am new to this. I have many files from b_ap00 to b_ap80, and I need to move them to folder 00 to 80 respectively, where b_ap00 is in folder 00, b_ap01 is in folder 01. On top of this, I need to rename the file once they are inside the folder to b_ot, and subsequently run it (ifort -o... (8 Replies)
Discussion started by: krustytherusty
8 Replies

9. Shell Programming and Scripting

Move only folders and skipping files

How do I move all folders and its contents from a directory A to another directory B, skipping all files in Directory A ? ---------- Post updated at 12:53 PM ---------- Previous update was at 12:42 PM ---------- Ok. Got it. mv /A/*/ /B/ (1 Reply)
Discussion started by: DHeisenberg
1 Replies

10. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies
JPEGICC(1)						      General Commands Manual							JPEGICC(1)

NAME
jpegicc - little cms ICC profile applier for JPEG. SYNOPSIS
jpegicc [options] input.jpg output.jpg DESCRIPTION
lcms is a standalone CMM engine, which deals with the color management. It implements a fast transformation between ICC profiles. jpegicc is little cms ICC profile applier for JPEG. OPTIONS
-b Black point compensation. -c <0,1,2,3> Precalculates transform. (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1] -g Marks out-of-gamut colors on softproof. -h <0,1,2> Show summary of options and examples. -i profile Input profile (defaults to sRGB). -m <0,1,2,3> SoftProof intent. -n Ignore embedded profile. -p profile Soft proof profile -o profile Output profile (defaults to sRGB). -q <0..100> Output JPEG quality. -t <0,1,2,3> Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute). -v Verbose. EXAMPLES
To color correct from scanner to sRGB: jpegicc -iscanner.icm in.jpg out.jpg To convert from monitor1 to monitor2: jpegicc -imon1.icm -omon2.icm in.jpg out.jpg To make a CMYK separation: jpegicc -oprinter.icm inrgb.jpg outcmyk.jpg To recover sRGB from a CMYK separation: jpegicc -iprinter.icm incmyk.jpg outrgb.jpg To convert from CIELab ITU/Fax JPEG to sRGB jpegicc -iitufax.icm in.jpg out.jpg NOTES
For suggestions, comments, bug reports etc. send mail to info@littlecms.com. SEE ALSO
tifficc(1), icc2ps(1), icclink(1), icctrans(1), wtpt(1) AUTHOR
This manual page was written by Shiju p. Nair <shiju.p@gmail.com>, for the Debian project. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWlcms | +--------------------+-----------------+ |Interface Stability | Uncommitted | +--------------------+-----------------+ NOTES
Source for LCMS is available on http://opensolaris.org. September 30, 2004 JPEGICC(1)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy