FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 06-25-2008, 03:08 PM
Grant
 
Default Quick script request

Feel free to ignore me here, but if anyone could whip out a quick
script for this I would really appreciate it.

I need to move any files from dir1 to dir2 if they don't already exist
in dir2 with a slightly different filename. The dir1 files are named
like a-1.jpg and the dir2 files are named like a-1_original.jpg.

- Grant
--
gentoo-user@lists.gentoo.org mailing list
 
Old 06-25-2008, 03:28 PM
Alex Schuster
 
Default Quick script request

Grant asks:

> Feel free to ignore me here, but if anyone could whip out a quick
> script for this I would really appreciate it.

Whipped. Be sure to test it, because I did not Remove the echo statement
when you are sure it works.

> I need to move any files from dir1 to dir2 if they don't already exist
> in dir2 with a slightly different filename. The dir1 files are named
> like a-1.jpg and the dir2 files are named like a-1_original.jpg.

cd $dir1
for file in *
do
if ! [[ -f $dir2/${file%.*}_original.${file##*.} ]]
then
echo mv -v "$file" "$dir2/"
fi
done

Loop over all files. If not exists a file called dir2/${file%.*}_original.
${file##*/}, move $file. ${file%.*} removes the suffix from $file
(everything from the last dot on), while ${file##*.} removes everything
until the dot, leaving the suffix only. Be sure to use the correct path for
dir2, either absolute or with some ../ in it.

Alex
--
gentoo-user@lists.gentoo.org mailing list
 

Thread Tools




All times are GMT. The time now is 06:21 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org