bash script for renaming and moving
#1
Ok, i have been tyrying for a few dyas to get a bash script to rename all my fiels and move them. I have a very basic script that i dont even know how i got to work in the first place, but it does something to my files and its a start. What I want it to do is go through every folder under my Movies directory and rename my files to include tags for sddvd and whatever else would populate the media flags from just the filename. So here is what I have, again its not close to what I want but its what ive got from these confusing ass bash books.

#!/bin/bash

files=$ (ls -l | grep .m4v)
for x in $files
do
mv $x sddvd.$x
done

so this sort of works but it adds the sddvd tag infront of the file name(sddvd.havoc.m4v) needing it to look like(havoc.sddvd.m4v)


so when this was working correctly it would be fine for folder level, but i would also like to run it on my library.

So any help would be appreciated. im not looking for someone to do it for me and then im done with it. i would like to learn more about bash and would love to understand what commands do and and how they work. Im rambling so.......
Reply
#2
use sed to replace .m4v with .sddvd.m4v, like

mv $x `echo $x | sed -e 's/m4v/sddvd.m4v/g'`
Reply
#3
spiff Wrote:use sed to replace .m4v with .sddvd.m4v, like

mv $x `echo $x | sed -e 's/m4v/sddvd.m4v/g'`

worked like a charm on the .m4v

so that takes care of the .m4v, what about the .tbn, .nfo?

i read about the * but it doesnt work in the line

files=$ (ls -l | grep .m4v)

files=$ (ls -l | grep .*) doesnt do what i would expect it to (taking whatever after the .
Reply
#4
. means any char in a regexp. use \. if you mean a litteral .
Reply
#5
spiff Wrote:. means any char in a regexp. use \. if you mean a litteral .

putting this in the line does nothing

files=$ (ls -l |grep \.*)
for x in $files
do
mv $x `echo $x |sed -e's/m4v/sddvd.m4v/g'`
done

in this line
mv $x `echo $x |sed -e's/m4v/sddvd.m4v/g'`

would i need a mv $x `echo $x |sed -e's/ \.*/sddvd \.* /g'`

again im sorry to be so dumb, but this stuff is extremelly confusing in the books i bought
Reply
#6
You want to do something like:
mv $x `echo $x | sed "s/\..../.sddvd&/"`
\. -> the "." char
... -> 3 chars
& -> the pattern found

To be sure to take the last 3 chars (if there is another dot in the filename), you can add a "$" at the end:
mv $x `echo $x | sed "s/\....\$/.sddvd&/"`

This would work with foo.xxx.yyy
Reply
#7
You need to quote that appropriately or spaces and special symbols will make a mess.
Reply
#8
Beenje Wrote:You want to do something like:
mv $x `echo $x | sed "s/\..../.sddvd&/"`
\. -> the "." char
... -> 3 chars
& -> the pattern found

To be sure to take the last 3 chars (if there is another dot in the filename), you can add a "$" at the end:
mv $x `echo $x | sed "s/\....\$/.sddvd&/"`

This would work with foo.xxx.yyy

i didnt get this to work. This is what i have (pretty much what spiff said)that is working but its just pointless to have all these arguments to do someting one could do.


#!/bin/bash

files=$ (ls -l | grep .mv4)
fox x in $files
do
mv $x `echo $x | sed -e's/m4v/sddvd.720p.6ch.AC-3.m4v/g'`
done

files=$ (ls -l | grep .nfo)
fox x in $files
do
mv $x `echo $x | sed -e's/nfo/sddvd.720p.6ch.AC-3.nfo/g'`
done

files=$ (ls -l | grep .tbn)
fox x in $files
do
mv $x `echo $x | sed -e's/tbn/sddvd.720p.6ch.AC-3.tbn/g'`
done


this is fine for me for the moment, ive moved on to try and see how to run this in subfolders in my main movie folder
Reply

Logout Mark Read Team Forum Stats Members Help
bash script for renaming and moving0