I am facing some problem while developing the script.My input config.csv file contains the three columns namely pathname,filename,filetype.Based on the file type i have to use ftp command that is if filetype=csv then do ftp.
The input file is
Nice thought
but actually the external vendor puts this file into our server,we cannot make any changes to this file.. :rolleyes:
Actually I am thinking if i can create the copy of the source file(config.csv) and then use sed command(replacing the slashes) ...but then will sftp command will work properly??
I am not sure if this approach is proper or not
Anyone have better idea ...
Double the \ character from the input file and use the print -R command instead of echo :
$ cat config.csv
pathname,filename,filetype
\home\fir\dir,filename1,csv
\home\fir1\dir,filename2,csv
\home\fir4\dir,filename3,csv
\home\fir\dir6,filename4,dat
$ cat amey.ksh
#!/bin/ksh
head -5 config.csv | sed 's+\\+&&+g' | while read line
do
Type1=`echo $line | awk -F"," '{print $3}'`
Type=`echo $Type1 | tr [A-Z] [a-z]`
if [ $Type = 'csv' ]
then
DataFileName=`echo $line | awk -F"," '{print $2}'`
DataPath=`print -R "$line" | awk -F"," '{print $1}'`
print -R $DataPath
slash=`echo '\'`
filelocation=`echo $DataPath$slash$DataFileName`
echo do sftp -n
fi
done
$ amey.ksh
\home\fir\dir
do sftp -n
\home\fir1\dir
do sftp -n
\home\fir4\dir
do sftp -n
$
Your script can be rewritten in the following form :
typeset -l Type
head -5 config.csv | sed 's+\\+&&+g' |
while IFS=, read DataPath DataFileName Type
do
if [ "$Type" = 'csv' ]
then
FileLocation="$DataPath\\$DataFileName"
print -R $DataPath
print do sftp -n
fi
done