Find and move files parsed from cvs file

I need help with a bash script.
We have a directory of files which need to be renamed and moved to another directory based on filename information in a cvs file.

The contents of the cvs file are as follows:

A102345,abc123
A102347,dfg475

Where dfg475 is the basename without extension

Our source folder is:

Old/A/ABC/abc123.ai
Old/A/ABC/abc123.pdf
Old/D/DFG/dfg475.ai
Old/D/DFG/dfg475.pdf

We need to find abc123.ai and abc123.pdf...
and move them to New directory while renaming them:
A102345_abc123.ai and A102345_abc123.pdf

The resulting destination folder should look like:

New/A102345_abc123.ai
New/A102345_abc123.pdf
New/A102347_dfg475.ai
New/A102347_dfg475.pdf

I'm stuck at the first step of trying to find the files by parsing the csv file.

Can you explain the logic to construct the new prefix (A102345/A102347)?

The old files "abc123" are referenced in a new database solution which assigns them a new name "A102345". We need to rename the file appending the new prefix while retaining the old name so we will be able to search the file system for either the new prefix or the old name. The old name consisted of logical expression of customer "abc" and order "123". The new forced name "A102345" lacks any such intelligence.

If the construction of the new name is assigned by a database solution, how can we provide you a solution if we do not know it?

I think they're just obtained from the CSV file.

---------- Post updated at 03:30 PM ---------- Previous update was at 03:24 PM ----------

Try this:

while IFS="," read NEWNAME OLDNAME
do
        UPPER=$(echo "$OLDNAME" | tr '[a-z]' '[A-Z]')
        for EXT in ai pdf
        do
                if [ -f Old/${UPPER:0:1}/${UPPER:0:3}/${OLDNAME}.${EXT} ]
                then
                        echo mv Old/${UPPER:0:1}/${UPPER:0:3}/${OLDNAME}.${EXT} New/${NEWNAME}_${OLDNAME}.${EXT}
                fi
        done

        fi
done < file.csv

Remove the 'echo' once you know it does what you want.

The database generates the cvs file which we need to parse line by line.
The prefix to the new name is contained in the first field of the cvs file.
The second field in the cvs file is the basename of the original files minus extension.

Below is my novice and vain attempts thus far:

#!/bin/bash
INPUT=~/New_Names.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] & while read new old
do
#echo $old
find ~/Desktop/Arts/ -name "$old*" >> Results.txt
#previous command dose not produce results.
#would rather pipe search results to xargs & mv instead of outputing to .txt
###
#following command is an attempt to mv the files from the search results to New directory renaming
#them appending $new field data of csv to beginning of file names.
for f in `cat Results.txt`; do mv ./"$f" "./New/${$new%f}";
done <$INPUT
IFS=$OLDIFS

Here is one possible solution:

#!/usr/bin/ksh
typeset -u mFirst
typeset -u mPref
IFS=','
while read mFld1 mFld2; do
  mFirst=$(echo ${mFld2} | cut -c1)
  mPref=$(echo ${mFld2} | cut -c1-3)
  mNewFN=${mFld1}'_'${mFld2}
  mv /Old/${mFirst}/${mPref}/${mFld2}.ai /New/${mNewFN}.ai
  mv /Old/${mFirst}/${mPref}/${mFld2}.pdf /New/${mNewFN}.pdf
done < Inp_File

Essentially mine without all the error checking and not bothering to convert case...

Our source folder structure is more complex than I first stated.

/Server/ART/A/AHGK1/AHGK1FF0001_0200/ahgk1ff0023.pdf
/Server/ART/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.ai
/Server/ART/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.pdf
/Server/ART/B/BFKR3/BFKR3LC0001_0200/bfkr3lc0018.pdf
/Server/ART/C/CRU1/CRU1FF0001_0200/cru1ff0129.ai
/Server/ART/C/CRU1/CRU1FF0001_0200/cru1ff0129.pdf

The number of characters in the filename and path vary.
Therefore, I thought it necessary to use a find function with input from the csv file which has the basename minus extensions.
The follow script performs well on local files but crawls when run on files
from network shares.

#!/bin/bash
date +"DATE: %a %m/%d/%Y  TIME: %r  Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU.log
date +"DATE: %a %m/%d/%Y  TIME: %r  Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
date +"DATE: %a %m/%d/%Y  TIME: %r  Auto" >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
date +"DATE: %a %m/%d/%Y  TIME: %r  Auto" >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
#Directory for source files to br moved and renamed
src=/Volumes/Serve/Archive
#Directory in which the files are move to
dest=/Volumes/Serve/Art/
IFS=','
while read new old; do
	ai=$(find $src -name $old.ai)
	pdf=$(find $src -name $old.pdf)
	#Following varible is used to stamp the pdf file with the "New" number from the csv input
	pdfout="$dest$new"_"$(basename $pdf)"
	stamper=/Users/Admin/Desktop/TMP/stamp.pdf
	ait=$(find $src -name $old.ait)
	eps=$(find $src -name $old.eps)
	tiff=$(find $src -name $old.tiff)
	tif=$(find $src -name $old.tif)
	psd=$(find $src -name $old.psd)
	fh8=$(find $src -name $old.fh8)
	fh9=$(find $src -name $old.fh9)
	noExt=$(find $src -name $old)
	#This is where the pdf files get stamped with the "New" number
	echo $new" -> "$old" -> "$pdfout$(basename $pdf) >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
	gs -q -sDEVICE=pdfwrite -o $stamper -c "<< /PageSize [792 612]  >> setpagedevice 18 586 moveto /Helvetica-Bold_Italic findfont 14 scalefont setfont ("$new") show"
	pdftk $pdf stamp $stamper output $pdfout verbose | grep .pdf$ >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
	rm -f -v $pdf >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
	#The following moves the remaining file types if they exist.
	mv -v $ai $dest${new}'_'${old}.ai >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $ait $dest${new}'_'${old}.ait >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $eps $dest${new}'_'${old}.eps >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $tiff $dest${new}'_'${old}.tiff >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $tif $dest${new}'_'${old}.tif >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $psd $dest${new}'_'${old}.psd >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $fh8 $dest${new}'_'${old}.fh8 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $fh9 $dest${new}'_'${old}.fh9 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
	mv -v $noExt $dest${new}'_'${old} >> /Volumes/Serve/Users/Admin/Logs/SKU.log
done < /Users/Admin/Desktop/List.csv