Need small help

Hi,

i have a client requirement to post the files into generic folder named as "source".file identification is to retrieve Publication code (Instance name) from the file name.So thereafter we move the files to different instances of specific folders for the same unix server.(means if the file name as q1 we are going to move the file into q1 folder,if the filename as gf we are going to move the file into gf folder,if the filename as ac then we are going to move the file into cdsglobalac folder and soon..........)

Below are the instance names

1) q1
2) gf
3) ac
4) hi
5) bg and so on.........

I have developed a shell script about this and it is running successfully for the requirement. But client gave some modifications,If the file name comes as "Q1","GF","AC","HI","BG" then we need to move those files into error folder.How can achieve this to modify the existing shell script.

src_dir=/home/global/source
tgt_dir=/home/global
file_dir=/home/global/import-file-move-to-instances
now=`date +%Y%m%d`

if [[ -e $file_dir/file_move_import_serv.log ]];
then
rm -f $file_dir/file_move_import_serv.log
fi

cat $file_dir/ClientName_file.txt | awk '{ print $1 }' | while read q_dirs

do
echo $q_dirs

if [[ $q_dirs == 'q1' || $q_dirs == 'gf' ]];
then
cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/$q_dirs/import-serv/
else
cdsgq_dir=`echo $q_dirs | sed 's/global//' | awk '{print}'|tr '[A-Z]' '[a-z]'`
echo $cdsgq_dir 
cp $src_dir/import-serv/$cdsgq_dir*.txt  $tgt_dir/$q_dirs/import-serv/

if [[ $? -ne 0 ]];
then
echo "file copying failed,due to file not available"  >> $file_dir/file_move_import_serv.log
else
echo "file copied sucessfully into $q_dirs/import-serv directory"  >> $file_dir/file_move_import_serv.log
fi
fi
done


rm -f $src_dir/import-serv/*.txt

In ClientName_file.txt having the folder names as

q1
gf
cdsglobalac
cdsglobalhi
cdsglobalbg

Please help me in advance.

I have a requirement to move the client files into a separate folders.file names comes as
q1_20100327.txt
gf_20100327.txt
ac_20100327.txt
hi_20100327.txt
based on the filenames we need to move those files into folders.folder names are
q1,gf,globalac,globalhi. For above i have done the coding and executing successfully.

#!/bin/ksh
src_dir=/home/global/source
tgt_dir=/home/global
file_dir=/home/global/import-file-move-to-instances
error_dir=/home/global/error_folder
now=`date +%Y%m%d`

if [[ -e $file_dir/file_move_import_serv.log ]];
then
rm -f $file_dir/file_move_import_serv.log
fi

cat $file_dir/ClientName_file.txt | awk '{ print $1 }' | while read q_dirs

do
echo $q_dirs

if [[ $q_dirs == 'q1' || $q_dirs == 'gf' ]];
then
cp $src_dir/import-serv/$q_dirs*.txt  $tgt_dir/$q_dirs/import-serv/
else
cdsgq_dir=`echo $q_dirs | sed 's/global//' | awk '{print}'|tr '[A-Z]' '[a-z]'`
echo $cdsgq_dir 
cp $src_dir/import-serv/$cdsgq_dir*.txt  $tgt_dir/$q_dirs/import-serv/

if [[ $? -ne 0 ]];
then
echo "file copying failed,due to file not available"  >> $file_dir/file_move_import_serv.log
else
echo "file copied sucessfully into $q_dirs/import-serv directory"  >> $file_dir/file_move_import_serv.log
fi
fi
done


rm -f $src_dir/import-serv/*.txt

In ClientName_file.txt having the folder names as

q1
gf
globalac
globalhi
globalbg

But,Now the client want to say is if the filename comes as capitals Q1_20100327.txt/GF_20100327.txt
AC_20100327.txt/HI_20100327.txt then we need to move those files into error folder.

Any help is much appreciated.

Thanks in advance

you can try something like:

#!/usr/bin/ksh
source_dir=/home/forum/test/source
target_dir=/home/forum/test/target
error_dir=/home/forum/test/error

for file in $source_dir/*
do
	echo "Processing file ${file##*/}."
	t_file=${file##*/}
	t_name=${t_file%%_*}
	if [ -d $target_dir/$t_name ] ; then 
		mv $file $target_dir/$t_file && echo "Moved to Target Dir" || echo "Unable to move."
	else
		if [ "$t_name" = "$(echo $t_name | tr '[a-z]' '[A-Z]')" ]; then
			echo "$t_name found in UpperCase."
			mv $file $error_dir && echo "Moved to Error Dir" || echo "Unable to move."
		else
			echo "Dir $t_name has not found in Target Dir."	
		fi
	
	fi
	
done
/home/forum/test->ls source/*
source/DD_20100327.txt
source/aa_20100327.txt
source/bb_20100327.txt
source/cc_20100327.txt
source/ee_20100327.txt

/home/forum/test->ls target/*
aa
cc
dd
/home/forum/test->./move.ksh
Processing file DD_20100327.txt.
DD found in UpperCase.
Moved to Error Dir
Processing file aa_20100327.txt.
Moved to Target Dir
Processing file bb_20100327.txt.
Dir bb has not found in Target Dir.
Processing file cc_20100327.txt.
Moved to Target Dir
Processing file ee_20100327.txt.
Dir ee has not found in Target Dir.
/home/forum/test->

you can also create the target dir whenever it is not found. (depends on your requirement).