Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell scripting: String manipulation

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
0
0
US
Hi, I'm writing a shell script in which I need to solve this situation:
I have a string:
my_string="some_very_long_string" and I need to replace the last character of this string with a '0'. How can I do that?
And when I run this script, i read this string from the command line parameter so the string length is variable.
Also, is there a link that has useful string manipulation routines for shell scripting?
Thanks,
Sashi
 
in ksh [or any POSIX shell]

my_string="${my_string%%?}0"

or with sed:

my_string="echo ${my_string} | sed -e 's/\(.*\).$/\10/g'"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Try
newstring=`echo $oldlong_string|sed 's/.$/\0/g'`

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top