![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to parse a string efficiently | sandiego_coder | Shell Programming and Scripting | 4 | 05-13-2008 09:12 AM |
| Parse String Using Sed | racbern | Shell Programming and Scripting | 4 | 04-23-2008 09:14 AM |
| how to parse this string | hcliff | Shell Programming and Scripting | 13 | 04-02-2008 01:43 AM |
| parse a string variable | methos | Shell Programming and Scripting | 3 | 10-18-2005 01:18 PM |
| How to parse a string into variables | aquimby | Shell Programming and Scripting | 3 | 02-22-2005 05:37 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
||||
|
Quote:
Code:
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
|
|
|||
|
Code:
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/' |
|||
| Google UNIX.COM |