Solved

Korn shell function to substitute a string within a larger string based on given offset & length

Posted on 2004-09-01
5
657 Views
Last Modified: 2013-12-26
Korn shell function to substitute a string within a larger string based on given offset & length without using awk, Perl, or anything but pure korn shell. Example: Record 000RI01990305ABC12345678901234567890abcdefghiabcdefghi. I want to pass into the function this record, my new string of 991305XYZ, starting possition of  7 for a length of 9. Any ideas? Any assistance would be greatly appreciated.

0
Comment
Question by:rayskelton
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 250 total points
ID: 11959731
You can use "cut" to do the job"

eg:

NEWSTR="991305XYZ"
OLD="000RI01990305ABC12345678901234567890abcdefghiabcdefghi."

REC1=`echo $OLD | cut -c1-6`
REC2=`echo $OLD | cut -c15-`

NEWRECORD=${REC1}${NEWSTR}${REC2}

0
 

Author Comment

by:rayskelton
ID: 11959975
Is there any other built in function or parameter? One more note: I am using the old 88 version of korn shell.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11960043
"cut" will work for any vserion of *nix!

You can also use awk (substr()) function to do the job.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11961801
Sounds very much like a homework question, but I'll give you benefit of the doubt

NEWSTR="991305XYZ"
OLD="000RI01990305ABC12345678901234567890abcdefghiabcdefghi."

echo ${OLD::6}$NEWSTR${OLD:10}

The above works in bash, but I'm pretty certain it should be fine for ksh.
0
 

Author Comment

by:rayskelton
ID: 11962230
The cut I have been using, but was looking more to a function. Perl works good for this, but looking for a simple solution native to many variations of Solaris. I guess piping the string into awk could work but haven't tried yet.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now