quick rename many files
ive wrote a script to convert all my *.wma into *.mp3, heres what it looks like
#----------- #!/bin/bash for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done for i in *.[Ww][Mm][Aa]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader $i && lame -m s audiodump.wav -o /home/cody/$i.mp3; done #-------------- this works well, however now i have song1.wma.mp3 song2.wma.mp3 what i want to do now is rename all the *.wma.* i tried this #--------- for i in *.wma.* ; do mv "$i" `echo $i | tr '.wma.' '.'`; done # --------- but all w's m's and a's are replaces with . can anyone tell me what ive done wrong? |
Try:
Code:
for i in *.wma.* ; do mv "$i" `echo $i | sed -e "s/\.wma$/.mp3/"`; done |
sorry but no go
this is my code now #---- #!/bin/bash for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done for i in *.[Ww][Mm][Aa]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader $i && lame -m s audiodump.wav -o /home/cody/$i.mp3; done for i in *.wma.* ; do mv "$i" `echo $i | sed -e "s/\.wma$/.mp3/"`; done #------ in the end im still left with song1.wma.mp3 an error is put to the console though, here it is mv: `01_falling_down.wma.mp3' and `01_falling_down.wma.mp3' are the same file cody@blue:~$ |
Two options:
script code: Code:
for file in *.wma.* ; do mv ${file} $( echo ${file} | sed 's@.wma@@' ) ; done Code:
rename ".wma" "" *.wma.* |
ok ive got it, thanks
can i just ask something else quick, how in the script can i put my current directory into a variable? eg, i have just gone to /home/cody/music/band i want to run the script that is now in /bin, but hhave it work in my current path |
You can store the current directory like so:
Code:
current_directory=$( pwd ) If you want the script to execute from some other location (not where you executed it from the command line), then you'll need to give it command line arguments and modify your script accordingly. Hope that's useful. |
ahh ok thanks a lot
|
the current directory is usually stored in a variable called
$PWD try also ( a bit neater ) Code:
for file in *.wma;do |
All times are GMT -5. The time now is 01:51 PM. |