1 |
Grant asks: |
2 |
|
3 |
> Feel free to ignore me here, but if anyone could whip out a quick |
4 |
> script for this I would really appreciate it. |
5 |
|
6 |
Whipped. Be sure to test it, because I did not :) Remove the echo statement |
7 |
when you are sure it works. |
8 |
|
9 |
> I need to move any files from dir1 to dir2 if they don't already exist |
10 |
> in dir2 with a slightly different filename. The dir1 files are named |
11 |
> like a-1.jpg and the dir2 files are named like a-1_original.jpg. |
12 |
|
13 |
cd $dir1 |
14 |
for file in * |
15 |
do |
16 |
if ! [[ -f $dir2/${file%.*}_original.${file##*.} ]] |
17 |
then |
18 |
echo mv -v "$file" "$dir2/" |
19 |
fi |
20 |
done |
21 |
|
22 |
Loop over all files. If not exists a file called dir2/${file%.*}_original. |
23 |
${file##*/}, move $file. ${file%.*} removes the suffix from $file |
24 |
(everything from the last dot on), while ${file##*.} removes everything |
25 |
until the dot, leaving the suffix only. Be sure to use the correct path for |
26 |
dir2, either absolute or with some ../ in it. |
27 |
|
28 |
Alex |
29 |
-- |
30 |
gentoo-user@l.g.o mailing list |