Renaming the files

Hello,
i wanna rename my files which names are written in movies.txt

films.txt = amovie
bmovie
cmovie
dmovie
emovie

and i wanna find this files and rename the files to 1_amovie
2_bmovie
3_cmovie
4_dmovie
5_emovie
Thanks for answers.

#! /usr/bin/sh

counter=1
for i in `cat movies.txt
do
mv $i ${counter}_$i
counter=`expr counter + 1`
done

awk '{ printf "mv %s %d_%s\n", $0, NR, $0 }' filename | ksh

Hi
The usage of awk was wonderful

Best Regards,
Rakesh UV

It does not work in my program because `find` command wrote the file names with their addresses to my file.
So my file include;
films.txt =
./1/2/amovie
./3/bmovie
./4/5/6/cmovie
./7/8/9/10/dmovie
./emovie
i have seen sed and awk command but i can not solve this problem

awk -F"/" -v OFS="/" ' { str=$0 ; $NF = NR "_" $NF ; print "mv " str " " $0 } ' file | ksh

it does not work so. i'm working in current directory and i wanna rename the file of any subdirectories.
i also tried to this code
mv `awk -F '/' '{print $NF;}' films.txt` x_`awk -F '/' '{print $NF;}' films.txt`
but it does not work too

i tried to write in this form but i cannot success
#
for i in `cat films.txt`
do
rename the files
done
#
films.txt =
./1/2/amovie
./3/bmovie
./4/5/6/cmovie
./7/8/9/10/dmovie
./emovie

#! /usr/bin/sh

counter=1
for i in `cat movies.txt
do
mv $i `dirname $i`/${counter}_`basename $i`
counter=`expr counter + 1`
done

Give a try with this if doesn't work..paste the log here :slight_smile:

Many thanks , it works well without using sed and awk.
but i have to learn this commands.
can anybody recommend me notes,websites or books to learn shell?

If you want to learn more on Sed/awk..go for this

http://www.vectorsite.net/tsawk.html

If you want to know more on Unix commands,
the below link will do..

http://linuxcourse.rutgers.edu/rute/node1.html

Thanks jacoden.. Thanks everbody

Thanks Jacoden...nice docs there...