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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut Final 2 Characters of String

Status
Not open for further replies.

danhodges99

IS-IT--Management
Feb 6, 2003
21
GB
Hi all,

I need to get rid of the final two characters of a string, eg:

myString='14504'

mymyNewString='145'

If you see what I mean...
The string will be ever changing, so an't just chop out the '04', needs to be the last two characters, any help is greatly appreciated!
 
try this ( untested)
LenMystr=${#MyString} # get length of the string
NewString=`echo $MyString|awk '{print substr($0,1,'"$LenMystr"' - 2)}'`

Dickie Bird (:)-)))
 
#!/bin/ksh

a='14504'

echo "a->[${a}] b->[${a%%??}]"


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top