| Author |
Message |
Dan Peduzzi *nix forums beginner
Joined: 07 Feb 2005
Posts: 2
|
Posted: Wed Feb 09, 2005 1:01 pm Post subject:
Re: replacing characters in ksh88 variables
|
|
|
Janis Papanagnou wrote:
| Quote: | Icarus Sparry wrote:
With ksh93 there are the ${var:offset} substitutions as well.
Yes, but since he explicitely stated ksh88 it's likely that he has
neither
a ksh93 available in his environment nor the possibility to install
one.
|
That's exactly the case. At this point, I can only look at ksh93
enhancements with extreme jealousy. :-)
The typeset -L technique was exactly what I needed in ksh88. Thank
you...everything is working perfectly.
Dan |
|
| Back to top |
|
 |
Janis Papanagnou *nix forums Guru
Joined: 24 Feb 2005
Posts: 450
|
Posted: Mon Feb 07, 2005 10:15 pm Post subject:
Re: replacing characters in ksh88 variables
|
|
|
Icarus Sparry wrote:
| Quote: | Dan Peduzzi wrote:
Is there a way to do this natively within ksh88, or should I look to a
UNIX utility for this sort of thing?
With ksh93 there are the ${var:offset} substitutions as well.
|
Yes, but since he explicitely stated ksh88 it's likely that he has neither
a ksh93 available in his environment nor the possibility to install one.
Janis |
|
| Back to top |
|
 |
Icarus Sparry *nix forums Guru
Joined: 19 Feb 2005
Posts: 342
|
Posted: Mon Feb 07, 2005 9:35 pm Post subject:
Re: replacing characters in ksh88 variables
|
|
|
On 2005-02-07, Janis Papanagnou <Janis_Papanagnou@hotmail.com> wrote:
| Quote: | Dan Peduzzi wrote:
For variables in the Korn shell, is it possible to replace characters
based upon their position only? For example, let's say I have
var="abcdefghi"
and I want to change the substring starting at position 4 and lasting 3
characters (to "123", in this case):
var="abc123ghi"
Is there a way to do this natively within ksh88, or should I look to a
UNIX utility for this sort of thing?
I have no ksh88 handy but think that this quick shot should outline
you at least one possibile way...
typeset var="abcdefghi"
typeset -i pos=4
typeset -i len=3
typeset subst="123"
typeset -L$((pos-1)) left1="$var"
typeset -L$((pos+len-1)) left2="$var"
print - "${left1}${subst}${var#$left2}"
|
With ksh93 there are the ${var:offset} substitutions as well.
var="abcdefghi"
newvar=${var:0:$((4-1))}"123"${var:$((4-1+3))}
The counts are from 0, hence the '-1' in the calculations.
Also works in bash 3.0 |
|
| Back to top |
|
 |
Janis Papanagnou *nix forums Guru
Joined: 24 Feb 2005
Posts: 450
|
Posted: Mon Feb 07, 2005 8:24 pm Post subject:
Re: replacing characters in ksh88 variables
|
|
|
Dan Peduzzi wrote:
| Quote: | For variables in the Korn shell, is it possible to replace characters
based upon their position only? For example, let's say I have
var="abcdefghi"
and I want to change the substring starting at position 4 and lasting 3
characters (to "123", in this case):
var="abc123ghi"
Is there a way to do this natively within ksh88, or should I look to a
UNIX utility for this sort of thing?
|
I have no ksh88 handy but think that this quick shot should outline
you at least one possibile way...
typeset var="abcdefghi"
typeset -i pos=4
typeset -i len=3
typeset subst="123"
typeset -L$((pos-1)) left1="$var"
typeset -L$((pos+len-1)) left2="$var"
print - "${left1}${subst}${var#$left2}"
Janis |
|
| Back to top |
|
 |
Dan Peduzzi *nix forums beginner
Joined: 07 Feb 2005
Posts: 2
|
Posted: Mon Feb 07, 2005 3:47 pm Post subject:
replacing characters in ksh88 variables
|
|
|
For variables in the Korn shell, is it possible to replace characters
based upon their position only? For example, let's say I have
var="abcdefghi"
and I want to change the substring starting at position 4 and lasting 3
characters (to "123", in this case):
var="abc123ghi"
Is there a way to do this natively within ksh88, or should I look to a
UNIX utility for this sort of thing? |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|