Hello everyone, I am a beginner in TCL, I would like to have some help dealing with data manipulation. I have the following text stored in a file:
#
#2345678$2345678$2345678$2345678$2345678$2345678$2345678$2345678$2345678
#
10.0000000.0000000.000000 230.7500000.5000000.0000000.812500
21.5000000.0000000.000000 262.0625000.3750000.0000000.457031
33.0000000.0000000.000000 253.3750000.2500000.0000000.203125
44.5000000.0000000.000000 304.6875000.1250000.0000000.050781
56.0000000.0000000.000000 216.0000000.0000000.0000000.000000
60.0000001.0000000.000000 230.7500000.5000000.0000000.812500
71.5000001.0000000.000000 291.5000001.2500000.0000000.062500
83.0000001.0000000.000000 322.6250000.9375000.0000000.144531
94.5000001.0000000.000000 244.1250001.0000000.0000000.140625
106.0000001.0000000.000000 216.0000000.0000000.0000001.000000
121.5000002.0000000.000000 222.2500002.0000000.0000000.562500
133.0000002.0000000.000000 283.1875001.5000000.0000000.285156
144.5000002.0000000.000000 244.1250001.0000000.0000001.140625
171.5000003.0000000.000000 222.2500002.0000000.0000001.562500
183.0000003.0000000.000000 222.2500002.0000000.0000001.562500
it consists into information stored in 8-digit format.
I already wrote the following script to read the txt file and to filter the information stored:
#
set filename03 "slot0to1.txt";
set open_file03 [open $filename03 "r"]
set read_file03 [read -nonewline $open_file03]
set split_file03 [split $read_file03 "\n"]
set i 1
foreach line $split_file03 {
set ID1 [string range $line 1 7 ]
set X1 [string range $line 8 15 ]
set Y1 [string range $line 16 23]
set Z1 [string range $line 24 31 ]
set ID2 [string range $line 32 39 ]
set X2 [string range $line 40 47 ]
set Y2 [string range $line 48 55 ]
set Z2 [string range $line 56 63 ]
set d1_2 [string range $line 64 71]
incr i
}
Now, I would like check if there are duplicates in the $ID2 (colums 32 to 39) and delete them, leaving the lower number in $ID1.
The output should looks like:
10.0000000.0000000.000000 230.7500000.5000000.0000000.812500
21.5000000.0000000.000000 262.0625000.3750000.0000000.457031
33.0000000.0000000.000000 253.3750000.2500000.0000000.203125
44.5000000.0000000.000000 304.6875000.1250000.0000000.050781
56.0000000.0000000.000000 216.0000000.0000000.0000000.000000
71.5000001.0000000.000000 291.5000001.2500000.0000000.062500
83.0000001.0000000.000000 322.6250000.9375000.0000000.144531
94.5000001.0000000.000000 244.1250001.0000000.0000000.140625
121.5000002.0000000.000000 222.2500002.0000000.0000000.562500
133.0000002.0000000.000000 283.1875001.5000000.0000000.285156
Thank you very much
#
#2345678$2345678$2345678$2345678$2345678$2345678$2345678$2345678$2345678
#
10.0000000.0000000.000000 230.7500000.5000000.0000000.812500
21.5000000.0000000.000000 262.0625000.3750000.0000000.457031
33.0000000.0000000.000000 253.3750000.2500000.0000000.203125
44.5000000.0000000.000000 304.6875000.1250000.0000000.050781
56.0000000.0000000.000000 216.0000000.0000000.0000000.000000
60.0000001.0000000.000000 230.7500000.5000000.0000000.812500
71.5000001.0000000.000000 291.5000001.2500000.0000000.062500
83.0000001.0000000.000000 322.6250000.9375000.0000000.144531
94.5000001.0000000.000000 244.1250001.0000000.0000000.140625
106.0000001.0000000.000000 216.0000000.0000000.0000001.000000
121.5000002.0000000.000000 222.2500002.0000000.0000000.562500
133.0000002.0000000.000000 283.1875001.5000000.0000000.285156
144.5000002.0000000.000000 244.1250001.0000000.0000001.140625
171.5000003.0000000.000000 222.2500002.0000000.0000001.562500
183.0000003.0000000.000000 222.2500002.0000000.0000001.562500
it consists into information stored in 8-digit format.
I already wrote the following script to read the txt file and to filter the information stored:
#
set filename03 "slot0to1.txt";
set open_file03 [open $filename03 "r"]
set read_file03 [read -nonewline $open_file03]
set split_file03 [split $read_file03 "\n"]
set i 1
foreach line $split_file03 {
set ID1 [string range $line 1 7 ]
set X1 [string range $line 8 15 ]
set Y1 [string range $line 16 23]
set Z1 [string range $line 24 31 ]
set ID2 [string range $line 32 39 ]
set X2 [string range $line 40 47 ]
set Y2 [string range $line 48 55 ]
set Z2 [string range $line 56 63 ]
set d1_2 [string range $line 64 71]
incr i
}
Now, I would like check if there are duplicates in the $ID2 (colums 32 to 39) and delete them, leaving the lower number in $ID1.
The output should looks like:
10.0000000.0000000.000000 230.7500000.5000000.0000000.812500
21.5000000.0000000.000000 262.0625000.3750000.0000000.457031
33.0000000.0000000.000000 253.3750000.2500000.0000000.203125
44.5000000.0000000.000000 304.6875000.1250000.0000000.050781
56.0000000.0000000.000000 216.0000000.0000000.0000000.000000
71.5000001.0000000.000000 291.5000001.2500000.0000000.062500
83.0000001.0000000.000000 322.6250000.9375000.0000000.144531
94.5000001.0000000.000000 244.1250001.0000000.0000000.140625
121.5000002.0000000.000000 222.2500002.0000000.0000000.562500
133.0000002.0000000.000000 283.1875001.5000000.0000000.285156
Thank you very much