Register
It is currently Fri Dec 19, 2014 10:47 am

Find and move files parsed from csv file data


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Jan 26, 2012 9:31 pm   

Joined: Thu Jan 26, 2012 9:23 pm
Posts: 1
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:
A10324687,ahgk1ff0023
A10324698,cru1ff0129

The source folder has the following hierarchy:
/Server/Archive/A/AHGK1/AHGK1FF0001_0200/ahgk1ff0023.pdf
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.ai
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.pdf
/Server/Archive/B/BFKR3/BFKR3LC0001_0200/bfkr3lc0018.pdf
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.ai
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.pdf

The results of the script moves and renames ahgk1ff0023* to:
/Server/Art/A10324687_ahgk1ff0023.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 following script performs well on local files but crawls when run on files
from network shares. Any suggestions?
Code:
#!/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


Last edited by Lloyd Boyette on Fri Jan 27, 2012 7:55 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Fri Jan 27, 2012 12:28 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
hi,

all this, imho, should be much more simple.
something like
Code:
while IFS=',' read new old
do
   find $where -name "$old.*" -exec sh -c 'what needs to be done; mv etc' \;
done < file.csv


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Exabot [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP