Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help on script to copy files from cd to disk and rename them

Status
Not open for further replies.

charld

Technical User
Oct 30, 2002
2
US
I am writing a script to copy a list of files from a cd to disk and rename the file.

i have a text file called mp3.txt that look like this

disk1:prince - Erotic City.mp3:00001.mp3:/music/pop
disk2:Enter Sandman - (metallica):00002.mp3:/music/metal

fields are defined by : where
filed1=name of a cd with mp3's on it.
field2=name of a mp3 on that cd
field4=what i want to rename that mp3 to after it's been
copied to disk
field5=place on disk i want to copy the mp3 to.

i am trying to write a script where i supply the name of the CD and the script will read mp3.txt and build a list of all files it needs to copy from that cd based on what's in mp3.txt then copy the file to the approprate location and rename them.

This is what i have so far. (This gives me a list of files i need to copy from the cd)

#!/bin/bash
# Build list of all file on the CD and store to a tmp file.
rm -rf /tmp/files_on_cd
rm -rf /tmp/db_files_on_cd
find /mnt/cdrom/ -type f -print >> /tmp/files_on_cd
#
# Search the mp3.txt and build a list of files to copy
# from CD that are listed in the mp3.txt.
grep $1 mp3.txt >> /tmp/db_files_on_cd
cat /tmp/db_files_on_cd

Script has to handle renaming files with spaces and other stuff in the name. something like this

#!/bin/bash
for f in *; do
g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
mv "$g" some_new_file_name
done



any ideas on how to put this all together or a better way of doing it.

thanks
 
I hope this is what you mean

#!/bin/bash
# Check if names in file are found on cd
# when so, copy them to the appropriate location
opt=/mnt/cdrom
IFS=:
while read xx
do
set $xx
if [ -f $opt/$2 ] ;then
echo cp $opt/$2 $4/$3
fi
done < mp3.txt

Succes
Gregor Gregor.Weertman@mailcity.com
 
YES that's it ;-)
thank you very much.
It dosent work with files that have spaces/strance characters in their names but i think i can figure that part out.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top