Solved

How do I extract a substring using tcl

Posted on 2006-07-10
3
5,653 Views
Last Modified: 2013-12-26
Hello, I need to extract a substring from another string using tcl.

I have tried using regexp without success.

Here is an example of what I need to do:

string1 = "22/OBGJ/123456_5.66:22/OBGJ/000123_7.134"

result

"22/OBGJ/123456_5.66"

I need to extract the entire substring upto but NOT including the ":" character.

Is there a simple solution for this?

Much thanks!
0
Comment
Question by:dongjinkim
3 Comments
 
LVL 6

Expert Comment

by:JJSmith
ID: 17077710

echo $string1 | cut -d":" -f1



cheers
JJ
0
 
LVL 3

Author Comment

by:dongjinkim
ID: 17077754
I should clarify that this is for tcl, not shell scripting.
I was not able to find a Tcl related channel, I apologize if this is not the best place to pose the question.
0
 
LVL 24

Accepted Solution

by:
slyong earned 500 total points
ID: 17078529

set x "22/OBGJ/123456_5.66:22/OBGJ/000123_7.134"   ;# This is your string
puts "[string range $x 0 [expr [string first ":" $x] - 1]]"        ;# [string first ":" $x] gives you the index of the first ":" and use [expr theposition - 1] to get the index - 1 position, then string range just extract out the substring
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question