Made a boo boo with filenames in bash script
Hi,
I've been writing a script that iterates through a folder (my kids videos) and strips out the first part of the filename, creates a folder of what's left, then moves the file into that folder.
...only, I haven't.
Instead, I've renamed the files like so:
Atlantis The Lost Empire.Disney Classic - 40 - Atlantis The Lost Empire.avi
from a file called:
Disney Classic - 40 - Atlantis The Lost Empire.avi
As you can see, I have missed the / from the mv command and instead of moving the files to a folder (that it created perfectly, in this case called "Atlantis The Lost Empire") it's prefixed the original file with the folder name.
I can't for the life of me work out how to reverse it.
The script I made is as such:
Code:
#!/bin/sh
for file in *Disney*.avi
do
i=${file%.*}
NEWDIR=`echo "$i" | sed 's/^.\{22\}//'`
mkdir "$NEWDIR"
mv "$file" "$NEWDIR"."$file"
echo $file
done
You can see what I've done, I put a . where I should have a /.
Now I need to reverse my **** up and put the files back how they were, THEN go back and run the corrected script.
I just can't work out how to remove everything back from the . in the new filename if you catch my drift.
Can anyone shed any light on this for me?
CPUs: AMD 64 * 4 2mhz, RAM: 8gb
HDD: 6tb HDD (2 USB 1tb, 3 SATA, 1 NAS)
GPU: NVIDIA 2 GeForce 7800 GTX SLIx2 (4x23 Philips Widescreen TFT)
OS: Ubuntu Studio 9.10 (rt) AMD64
Bookmarks