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
rince - 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 have a text file called mp3.txt that look like this
disk1
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