Hi,
I have a shell scripts which split a file based on the value on the 13th postion of the each line.
If the Value of the 13th position is 'H' this will go to one file and if value is 'D' then it will go to some other file.
My problem is that while reading from the file line per line ; its triming the space beteween two filds to one char space.Due to which my script is not able to find the desired char.
The script is as below:-
#!/usr/bin/ksh
CURRDATESTAMP=`date +%Y-%m-%d`
echo $CURRDATESTAMP
##########################
##########
##########
##########
##########
######
# SCRIPT: MTVload
# AUTHOR: Deepak
# DATE: 07/17/2008
# REVISED:
#
#
#
#
# PURPOSE:
#
#
##########################
##########
##########
##########
##########
######
#Mtv extract file directory
MTVFSDIR="/tempdstage/mbre
port_extra
ct"
MTVFTPDIR="$MTVFSDIR/mtv_f
tp"
#Mtv extract log directory
MTVLOGSDIR="$MTVFSDIR/log"
#Mtv stag folder directory
MTVSTAGEDIR="$MTVFSDIR/ext
ract_files
"
MTVLOG=$MTVLOGSDIR/$1".MTV
EXTRACT.LO
G."$CURRDA
TESTAMP
MTVARCH="$MTVFSDIR/archive
"
# removing files from stage folder
rm -f $MTVSTAGEDIR/*.*
if [ $? = 0 ]
then
echo "Deleted mtvload.progress file..."
fi
# Check for any process is running currently before initiating the loading process again
FOUNDFILE=`find $MTVSTAGEDIR -name "mtvload.progress"`
if [ -n "$FOUNDFILE" ]
then
MTVERROR="mtv Load in progress, wait for Completion."
#echo $MTVERROR
MTVERRNO=01
exit $MTVERRNO
else
> $MTVSTAGEDIR/mtvload.progr
ess
fi
# Check for mtv extract file "GLG6ZBCW.txt" there for loading or not in the inbound folder
FOUNDCNT=`ls $MTVFTPDIR/GLG6ZBCW.txt | wc | awk '{print $1}'`
if [ $FOUNDCNT -eq 1 ]
then
# Spliting of file start
echo "spliting start"
while IFS='\n' read Line
do
echo $Line
match_char=`echo $Line | cut -c 13 `
echo "match_char $match_char"
if test "$match_char" -eq "H"
then
echo "$Line" >> $MTVSTAGEDIR/gl_cash_stage
_header.tx
t
elif test $match_char -eq 'D'
then
echo "$Line" >> $MTVSTAGEDIR/gl_cash_stage
_detail.tx
t
else
echo "$Line" >> $MTVSTAGEDIR/gl_cash_stage
_reject.tx
t
fi
done < $MTVFTPDIR/GLG6ZBCW.txt
echo "Spliting of file end"
else
echo "MTV FTP folder empty... Exiting Gracefully..... "
fi
# Loading to satge table from datstage jobs
# Loading to satge tables to target tables from datastage jobs
# Archiving process of files
#zipping of files
#gzip $MTVFTPDIR/*.txt
#move the file to archive follder
#mkdir $MTVARCH/$CURRDATESTAMP
#chmod 777 $MTVARCH/$CURRDATESTAMP
#mv $MTVFTPDIR/*.gz $MTVARCH/$CURRDATESTAMP
if [ $? = 0 ]
then
echo "mbtv zip file moved to archive... "
fi
# Remove files from more than 31 days
# removing mtvload.progress file from stage folder
rm -f $MTVSTAGEDIR/mtvload.progr
ess
if [ $? = 0 ]
then
echo "Deleted mtvload.progress file..."
fi
STAMP=`date +%Y-%m-%d:%H-%M-%OS`
echo "Job Completed !!!..."
#everything goes well, exit with 0
Please find the attached file to whom i am spliting .
can anybody help me out.
thanks
deepak
Start Free Trial