?
Solved

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

Posted on 2004-09-01
5
Medium Priority
?
718 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
[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
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 1000 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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