Split in tcl script

Hi All,

I have a string

re_em="NODE_NAME=ABCDEF;NODE_TYPE=ghijkl;CIRCLE=jkl;Serving_Circle=abcdefghthjk;DOMAIN_TYPE=1234;REGION=12345;ZONE=12334;SOURCE_TYPE=dhfkdkfjdjf"

I want to split this string and convert it into array so that i can easily access any value like NODE_NAME or NODE_TYPE

Thanks

I suppose your columns remain fixed..

awk -F"[;\"]" ' { print $3  } '

---------- Post updated at 07:16 PM ---------- Previous update was at 07:14 PM ----------

and if you want search based on your choice

awk -F"[;\"]" ' { for(i=1;i<=NF;i++) { if($i ~ "NODE_NAME" ) { print $i }  } } '

Hi.

Here is something to get you started with your request in tcl:

#!/usr/bin/env tclsh

# @(#) s1     Demonstrate associative array.

set version [ info tclversion ]
set message " Hello, world from tclsh ($version)"
puts stdout $message

set s "NODE_NAME=ABCDEF;NODE_TYPE=ghijkl;CIRCLE=jkl;Serving_Circle=abcdefghthjk;DOMAIN_TYPE=1234;REGION=12345;ZONE=12334;SOURCE_TYPE=dhfkdkfjdjf"

# split the line into strings separated by ";"
set pairs [split $s ";"]
puts "sample pair at index 1 = [lindex $pairs 1]"
puts ""

# break apart key=value pairs into associative array a
for {set x 0} {$x < [llength $pairs]} {incr x} {
  set p [ split [lindex $pairs $x] "=" ]
  puts $p
  set a([lindex $p 0]) "[lindex $p 1]"
}
puts ""

puts "sample associative array a of key SOURCE_TYPE = value $a(SOURCE_TYPE)"

exit 0

producing:

% ./s1
 Hello, world from tclsh (8.4)
sample pair at index 1 = NODE_TYPE=ghijkl

NODE_NAME ABCDEF
NODE_TYPE ghijkl
CIRCLE jkl
Serving_Circle abcdefghthjk
DOMAIN_TYPE 1234
REGION 12345
ZONE 12334
SOURCE_TYPE dhfkdkfjdjf

sample associative array a of key SOURCE_TYPE = value dhfkdkfjdjf

See web sites such as Listing of Directory /man/tcl/TclCmd/ and man pages for details.

Best wishes ... cheers, drl