Solved

ksh - How do I right pad a string in the old version of ksh

Posted on 2004-10-04
15
744 Views
Last Modified: 2013-12-26
ksh - How do I right pad a string in the old version of ksh. I must have a fixed record length of X number of bytes. I am inserting and editing this record, but must end up padded to X number of bytes.
0
Comment
Question by:rayskelton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 21

Expert Comment

by:tfewster
ID: 12221837
printf "%-Xs" $yourtext
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12223988
Depends exactly what you mean by "old version of ksh".

From memory, I think you can do:

typeset -R20 string='abcde'
echo "$string"


0
 

Author Comment

by:rayskelton
ID: 12226639
The printf works good, but I think my problem is a litter more than I first thought. I think my problem stems from a read and I need to convert the read to something else. Below is a snippet of what I am referencing.


This is my current read of a file which I test conditions and edit records. None of my trailing spaces are read from this line.
 cat $AIXX_MVR_RESULT_FILE | while IFS="\n" read resLine

Below is a line, which reads without trimming the trailing white spaces.
     resLine=$(echo "$line" | cut -c0-$editOffset)

How do I incorporate the above line in a while loop as the cat is doing above.



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12227015
use 'read -r resLine' instead of 'read resLine'
0
 

Author Comment

by:rayskelton
ID: 12227181
The -r didn't work for me. The -d option is what I need, but am running the pre 88 version of ksh. Any other ideas? The snippet below gives a better picture of what I am doing.



###########################################################
# Replace the result file posn/bsn with the previouly
# captured posn/bsn for AIXX Result
#########################################################
            cat $AIXX_MVR_RESULT_FILE | while read resLine
              do
               aixxRecType=$(echo $resLine | cut -c0-2)
               if [ $aixxRecType == "04" ]; then
                 print "04 Record type found:"$aixxRecType
                 # Substitute posn/bsn
                 typeset substitutionLength=29
            
                 returnedSubString=" "
             print "RESLINE befory function:"$resLine
                 SubStringFunc1 $resLine $QUOTEBACK 5 $substitutionLength
                fi
             resLine=$(printf "%-80s" $resLine)
             print $resLine >>$RESULT_HOME/$UNQ_AIDS_RESULT.aidsMvr
             resLine=" "
              done
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12227281
Yeah, use a modern version of ksh. http://www.research.att.com/sw/download/
0
 

Author Comment

by:rayskelton
ID: 12227360
I can't use a newer version. I am locked in a large corporate environment with many Sun boxes standardized to the old version. I must use what the sysadmins have standardized the company around.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12227411
In that case, don't write your program in ksh. How about Perl?
0
 

Author Comment

by:rayskelton
ID: 12227470
Perl would make it easier, but cannot use Perl. I cannot change the scripting language or version to solve this problem. I must find a simple solution to prevent a file read from stripping the white spaces and this problem cannot be that difficult.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12227755
You might think the problem is not that difficult, but there's a reason that Dave Korn decided to the semantics of read 16 years ago.

How about something like this:
  cat $AIXX_MVR_RESULT_FILE | sed 's/$/|/' | while IFS="|" read resLine junk
0
 

Author Comment

by:rayskelton
ID: 12228884
I can't get " cat $AIXX_MVR_RESULT_FILE | sed 's/$/|/' | while IFS="|" read resLine junk" to work or any variation. I also tried replacing the sed with cut and no difference.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12229192
Hmm, works fine for me. But I don't have any systems with a ksh earlier than ksh88.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12230520
What version of Solaris are you running?  They must be *very* old if they don't have ksh88 or better on them.
0
 

Author Comment

by:rayskelton
ID: 12231219
The version is 11/16/88 and is the same on around 25 Sun boxes. It's a no issue trying to upgrade versions on these machines affecting potentially hundreds of developers and hundreds of mission critical applications. Not worth the breath.
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 500 total points
ID: 12237222
Umm, this is ksh88 (hence the 88), and is the same version I tested my read -r line on.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 116
Named range not carried over 10 71
Change to event 1 136
ERP and the other system process verification 5 25
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question