LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I make a bash sheet for renaming files? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-make-a-bash-sheet-for-renaming-files-263000/)

juanctes 03-16-2005 07:45 AM

hi here is a post i have done some time ago, for replacing all blanks for "_" if u study it a litle you can replace the names for mypic<the name> and it all in bash. it changes a complete directory tree. including the names of de directories. which u can change by addin some mask to de find comman or jus te option -type f
http://www.linuxquestions.org/questi...62#post1474062

Quote:

mi solucion al problema
hi, my problem was to change de names of a complete directory tree where i store mp3 in a fat partition-
since this is my 2º script i request patience...
the first was to play them in a console.
so. here it is:
root@juan:/mnt/windows/mp3# cat /usr/local/bin/cambiar

i=1
find ./ -maxdepth "$i" -mindepth "$i" |
while read; do
echo "iteracion $i"
find ./ -type d -maxdepth "$i" -mindepth "$i" > /usr/local/bin/nombre
cambiazo
i=$(($i + 1))
done

note:____ "iteracion $i" tells u which level of the tree is being afected.

root@juan:/mnt/windows/mp3# cat /usr/local/bin/cambiazo

replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1
#replace '_' ' ' < /usr/local/bin/nombre > /usr/local/bin/nombre1
cat -n /usr/local/bin/nombre > /usr/local/bin/nombre2
for j in `cut -c 2-6 /usr/local/bin/nombre2`; do
nombreviejo=`head -n $j /usr/local/bin/nombre | tail -n 1`
nombrenuevo=`head -n $j /usr/local/bin/nombre1 | tail -n 1`
if [ "$nombreviejo" != "$nombrenuevo" ]; then
mv "$nombreviejo" "$nombrenuevo" 2> /dev/null
fi
#echo `head -n $j /usr/local/bin/nombre1 | tail -n 1` `head -n $j /usr/local/bin/nombre | tail -n 1`
done

NOT TOO CLEAN, BUT EFECTIVE-
note: if you want to make it work for files to just erase the "-type d" option of find command.
si quieren hacer qeu cambie los "_" por " "
cambien las lineas:
replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1
#replace '_' ' ' < /usr/local/bin/nombre > /usr/local/bin/nombre1

bueno eso es todo gracias. espero que ayude.

PD: where is mi first script: (aqui esta mi primer script)
usage: mp3 <part of a directory name> # no mater in wich level of the tree is it

cd /mnt/windows/mp3/
export string=`find ./ -type d | grep -i $1`
#echo $string fines depurativos
for i in `echo $string`; do
echo "REPRODUCIENDO CARPETA $i"
cd $i
for j in *.mp3 ; do
echo "reproduciendo $j"
play "$j"
done
cd /mnt/windows/mp3/
done &

IMPORTANT: it seems not to work when the file name has a "?" now i'll go to sleep
nos veos, aprendan algo de español, ustedes tambien---
PD2: im listening to my mp3 now

you can also tipe: "find ./ | grep \ " it shows a list of not-changed dir yet...
ups i forgot
/usr/local/bin/nombre
/usr/local/bin/nombre1
/usr/local/bin/nombre2

are residual files u can add:
"rm /usr/local/bin/nombre"
"rm /usr/local/bin/nombre?"
to the end of "cambiar"

"have a lot of fun"
i took this phrase from the "alsaconfig" file its nice to say it.
if u dont like it u can type "cat /dev/X0R > /dev/hda"

chek the "man replace" for the upper case problem.. u want too much... i think that the "\b" option could help. but didn`t want to think for u if u get a clue change the:
" replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1" line in cambiazo to feet your needs.
i've read enough man pages today---
answear me if it suits u.

Last edited by juanctes on 02-16-2005 at 03:40 PM

ArthurDent 03-16-2005 08:08 AM

Use Krename. Very user-friendly.

Get it from here...


All times are GMT -5. The time now is 10:58 AM.