The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 12:18 PM
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 9 05-29-2008 06:47 AM
Sed-Special character replacement usshell Shell Programming and Scripting 3 05-22-2008 07:06 AM
Character replacement piooooter Shell Programming and Scripting 2 09-05-2007 11:48 PM
Help needed in character replacement in Korn Shell stevefox Shell Programming and Scripting 8 03-29-2007 08:59 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-24-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
KSH - Character Replacement

Hey all.

Easy question.

I have a (ksh) varaible x. It contains the following (for example): N557788

I want to replace the "N" with a "-".

I've done this before but for the life of me I cannot remember how I did it.

Thanks.

mtw
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-24-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
I had an epiphany! (actually I just remembered what I had done earlier)

This is what I was looking for; nice and simple:

x=`print $4 | sed 's/N/-/'`

With $4 being passed in from another script which is N557788...

Thanks.
Reply With Quote
  #3 (permalink)  
Old 09-24-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,390
You can do it all in shell
(without calling external utilities, like sed for example), but it depends on your ksh version.
Is N in fixed or variable position?
One or many occurrences?

With ksh93(dtksh on Solaris):

Code:
$ print ${.sh.version}
Version M 1993-12-28 r
$ v="N557788"
$  print -- ${v/N/-}
-557788
For older versions of ksh the solution depends on the answers of the above questions.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0