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

Subtring in solaris

Status
Not open for further replies.

umeman

Technical User
Oct 2, 2001
59
US
How do I get a subtring in a UNIX Korn shell script:

STRING1='ABCD01'

I want to assign STRING2='ABCD' derived from STRING1

Any help appreciated

-u-
 
You could do ...

STRING1='ABCD01'
STRING2=$(echo $STRING1 | cut -c1-4)

Greg.
 
umeman:

I like greg's solution better, but ....


string1="ABCD01"
string2=$(echo $string1|awk ' {
print substr($0, 1, 4)
} ')
echo $string2

Regards,

Ed
Schaefer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top