String parse question

I have a string of data that looks like this:

[1] private.enterprises.954.1.1.1.1.1.2618 \(OctetString\): U [2] private.enterprises.954.1.1.1.1.2.2618 \(OctetString\): 2618

I am trying to parse the string to only return the values after the ":". Ex from above "U" and "2618".

Any suggestions?

One way:

$ cat string
#! /usr/bin/ksh

string="[1] private.enterprises.954.1.1.1.1.1.2618 \(OctetString\): U [2] private.enterprises.954.1.1.1.1.2.2618 \(OctetString\): 2618"
echo string = $string
string=${string#*: }
first=${string%% *}
second=${string##*: }
echo first = $first
echo second = $second
exit 0
$ ./string
string = [1] private.enterprises.954.1.1.1.1.1.2618 \(OctetString\): U [2] private.enterprises.954.1.1.1.1.2.2618 \(OctetString\): 2618
first = U
second = 2618

In any POSIX shell (bash, ksh, ash, etc.), you can use parameter expansion to extract parts of a string:

var="abc:def ghi jkj:lmn opq"
left1=${var%%:*} ## Everything to the left of the first colon
left2=${var%:*} ## Everything to the left of the rightmost colon
right1=${var##* } ## Everything to the right of the rightmost space
right2=${var#* } ## Everything to the right of the first space

Thanks for the help. I will give it a try.

Assuming that the variable var contains the above data

echo $var | awk -F: '{print substr($2,1,2)" " $3;}'

echo "[1] private.enterprises.954.1.1.1.1.1.2618 \(OctetString\): U [2] private.enterprises.954.1.1.1.1.2.2618 \(OctetString\): 2618" | sed 's/\(.*\): \(.*\) \[\(.*\): \(.*\)/\2\
\4/'