Gentoo Archives: gentoo-user

From: Alex Schuster <wonko@×××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Quick script request
Date: Wed, 25 Jun 2008 15:28:38
Message-Id: 200806251728.23051.wonko@wonkology.org
In Reply to: [gentoo-user] Quick script request by Grant
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