I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user.
Bear with me...
I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync to copy files from directories but i don't know how to move or copy the 20 jpgs into the corresponding 20 directories which have 01-20 as identifiers.
In other words, each jpg goes into a ]01_filename_100px
02_filename_200px...so on til
20_filename _3000px
I have searched the web for several days without an intelligent answer...
I believe I need an expression or a loop to accomplish this. I tried applescript, automator and rsync but I reached frustration...
Ideally I would like to use a standard mac process, like terminal.
Can someone point me to a resource? a book? a link?
I am rewriting my question for clarity. Please, please help me!
I have the following challenge which I am trying to solve via bash with an expression that takes the suffix of the file and the prefix of the folder as a target or another type of loop formula.
I'd like to move files with sequential numbers into existing sequential numbered directories. like:
filename_01.jpg into folder name 01_foldername
filename_02.jpg into folder name 02_foldername
filename_03.jpg into folder name 03_foldername... so on...
I tried the following without much success
for f in *files2folders; do
target_part="${E[0-9][0-9]}"
target="${E[0-9][0-9]}"
mv "$f" -t "${target} "*
done
I am a new linux student and would love explore this solution.
Could someone help me with a link or a tutorial to accomplish this?
I am using my shell terminal in a mac os environment.
The error I get from terminal:
-bash: E: bad array subscript
-bash: E: bad array subscript
The files and directories are located on my desktop in a directory called "files2folders"
After changing directory to "files2folders", the for loop runs across all .jpg files. The "number suffixes" are extracted by means of two shell's "Parameter Expansion / Remove matching prefix (suffix) pattern" ( man bash ), then the mv command is constructed using the FN and NR variables, relying on the assumption that there will be only ONE matching directory.
Thank you nezabudka,
I can't wait to try that.
Question, what if there is a letter code preceding the suffix on the filename like filename_wa01.jpg? would i ruin the code if i added the "wa" to the string? Sorry i am newbie...
Might be wise not to rely on the directories' suffixes correspond to their "sequential number" which equals the files' "sequential numbers". And, check if a corresponding file exists at all to avoid failure if absent:
for DN in 0[1-4]*
do TMP="*[!0-9]${DN/%_*}.jpg"
[ -f $TMP ] && echo mv $TMP $DN
done
mv 1244081312562_02.jpg 02_webasset_200
mv 1244081312562_03.jpg 03_webasset_300
mv 1244081312562_04.jpg 04_webasset_400