Advertisement

08.08.2008 at 04:31AM PDT, ID: 23632308
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

how to retain spaces between fields of a fixed length file while reading in shell scripts

Asked by deepak_tyco in KornShell (ksh)

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/mbreport_extract"
MTVFTPDIR="$MTVFSDIR/mtv_ftp"
#Mtv extract log directory
MTVLOGSDIR="$MTVFSDIR/log"
#Mtv stag folder directory
MTVSTAGEDIR="$MTVFSDIR/extract_files"
MTVLOG=$MTVLOGSDIR/$1".MTVEXTRACT.LOG."$CURRDATESTAMP
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.progress
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.txt
               elif test $match_char -eq 'D'
               then
                 echo "$Line"  >> $MTVSTAGEDIR/gl_cash_stage_detail.txt
              else              
              echo "$Line"  >> $MTVSTAGEDIR/gl_cash_stage_reject.txt
            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.progress
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
deepakStart Free Trial
Attachments:
 
this is the file i am trying to split in to teo files
 
[+][-]08.08.2008 at 05:45PM PDT, ID: 22194617

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: KornShell (ksh)
Sign Up Now!
Solution Provided By: dmadole
Participating Experts: 1
Solution Grade: B
 
 
[+][-]08.12.2008 at 03:45AM PDT, ID: 22211591

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 06:58AM PDT, ID: 22213112

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628