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!

Spiltting a String

Status
Not open for further replies.

cfoly

Programmer
Oct 9, 2002
3
SE
Hi,

I have a string which I need to split in relation to certain characters. I know that these characters are unique within the string.

String "...DEL_v...". I want to split the string into two seperate strings where the underscore appears above, leaving
me with String 1="...DEL" and string 2="v...". There may be other underscores in the beginning or the end of the string also.

Help appreciated.

/Beginner.
 
You could try:

echo $string | awk -F"DEL_" ' {if (NF > 1) { print $1, $2}}'`

Don't know if that's what you want.
 


str1=aaaaaaDEL_Vbbbbbbbb
str2=`echo $str1|sed -e 's/^.*DEL_v/v/'`
-> aaaaaDEL
str1=`echo $str1|sed -e 's/DEL_v.*/DEL/'`
-> Vbbbbbbbb vox clamantis in deserto.
 
#!/bin/ksh

a="...DEL_v..."

echo "->[${a}]"
echo "1->[${a%%_*}]"
echo "2->[${a##*_}]"
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top