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

Tcl: how to split string by blank lines

Status
Not open for further replies.
Feb 5, 2012
6
NL
hello All,

could you please help me split a string into a list using as a delimiter a blank line ? split using "\n\n" doesn't seem to work. an example of such a string is the following :

Group: 1.1.1.1, (?)
Source: 2.2.2.2 (?)
Rate: 5382 pps/58470 kbps(1sec), 58469 kbps(last 30 secs), 58327 kbps(life avg)

Group: 3.3.3.3, (?)
Source: 4.4.4.4 (?)
Rate: 9150 pps/99399 kbps(1sec), 99398 kbps(last 30 secs), 85769 kbps(life avg)

Group: 5.5.5.5, (?)
Source: 6.6.6.6 (?)
Rate: 474 pps/5163 kbps(1sec), 5164 kbps(last 30 secs), 5144 kbps(life avg)

 
Hi there,
The split procedure will split by any of chars.
So practically [split $x "\n\n"] is the same as [split $x "\n\n"]

One idea will be to replace the "\n\n" sequence with a char that does not exists in your string a nd to use the split after.
E.g. "\x00" is a good one.
Let's assume that that in "x" variable you have your string.
Then to get the list that you want:
set list_x [split [string map [list "\n\n" "\x00"] $x] "\x00"]


Best Regards,
Marcel

___
____
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top