Gentoo Archives: gentoo-user

From: Etaoin Shrdlu <shrdlu@×××××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Quick script request
Date: Wed, 25 Jun 2008 15:36:18
Message-Id: 200806251731.59517.shrdlu@unlimitedmail.org
In Reply to: [gentoo-user] Quick script request by Grant
1 On Wednesday 25 June 2008, 17:08, Grant wrote:
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 > I need to move any files from dir1 to dir2 if they don't already exist
7 > in dir2 with a slightly different filename. The dir1 files are named
8 > like a-1.jpg and the dir2 files are named like a-1_original.jpg.
9
10 Try this (untested)
11
12 #!/bin/bash
13
14 cd /dir1
15
16 for i in *; do
17 if [ ! -f "/dir2/$i" ]; then
18 bn=${i%.*}
19 ext=${i##*.}
20 nn=${bn}_original.${ext}
21 mv -- "$i" "/dir2/$nn"
22 fi
23
24 done
25
26
27 For each file in dir1, say a-1.jpg, this look if a file with the same
28 name exists in dir2. If not, it moves it to dir2 with the new name of
29 a-1_original.jpg. I hope I got that right.
30 --
31 gentoo-user@l.g.o mailing list