Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
moving specific files to their homes
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
xante
Apprentice
Apprentice


Joined: 23 Aug 2004
Posts: 229

PostPosted: Sat Aug 26, 2006 6:50 pm    Post subject: moving specific files to their homes Reply with quote

i have files:

saggy_-_test.ext
saggy_-_test2.ext
skimpy_-_test.ext
simple_-_test.ext
simple_-_test2.ext
simple_-_test3.ext

and directories:

saggy
skimpy
simple

I want to move the files to their coordinating homes but the trick is i have 13000 files and 1200 directories, any simple method?
Thank you in advance
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sat Aug 26, 2006 7:59 pm    Post subject: Reply with quote

something like
Code:
#!/bin/sh


cd into/the/right/directory/first
for filename in *; do
    mv -v ${filename} path/to/${filename%%_-_*}
done
should do it
_________________
The End of the Internet!
Back to top
View user's profile Send private message
dobysirius
n00b
n00b


Joined: 27 Nov 2005
Posts: 69
Location: Sofia, Bulgaria

PostPosted: Sat Aug 26, 2006 9:14 pm    Post subject: Reply with quote

Though you will need to make all the directories first
Code:
#!/bin/sh


cd into/the/right/directory/first
for filename in *; do
    mkdir -p path/to/${filename%%_-_*}
    mv -v ${filename} path/to/${filename%%_-_*}
done

(or something similar, I'm not particularly good at shell scripting)

Edit: Oh, nevermind, looks like the dirs already exist from the way the post is worded
Back to top
View user's profile Send private message
xante
Apprentice
Apprentice


Joined: 23 Aug 2004
Posts: 229

PostPosted: Sat Aug 26, 2006 10:46 pm    Post subject: Reply with quote

Thats correct, I was learning sed and designed this:
Code:
mkdir -p `ls --color=none | sed -e s/_-_.*/\//g | cut -f 1 | sort | uniq`

Thank you for your post, ill give it a try.
Although simple sed line, it was the process of getting there that was funner :P
Back to top
View user's profile Send private message
xante
Apprentice
Apprentice


Joined: 23 Aug 2004
Posts: 229

PostPosted: Wed Sep 13, 2006 3:07 am    Post subject: Reply with quote

I did give your script a try, it was unsuccessful, Thank you for the motivation though, I will be doing a bit of shell scripting myself here to get familar with it, when I do right one up, I shall post here.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum