View previous topic :: View next topic |
Author |
Message |
xante Apprentice
Joined: 23 Aug 2004 Posts: 229
|
Posted: Sat Aug 26, 2006 6:50 pm Post subject: moving specific files to their homes |
|
|
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 |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Sat Aug 26, 2006 7:59 pm Post subject: |
|
|
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 |
|
|
dobysirius n00b
Joined: 27 Nov 2005 Posts: 69 Location: Sofia, Bulgaria
|
Posted: Sat Aug 26, 2006 9:14 pm Post subject: |
|
|
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 |
|
|
xante Apprentice
Joined: 23 Aug 2004 Posts: 229
|
Posted: Sat Aug 26, 2006 10:46 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
xante Apprentice
Joined: 23 Aug 2004 Posts: 229
|
Posted: Wed Sep 13, 2006 3:07 am Post subject: |
|
|
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 |
|
|
|