在 MSQ 数据中查找 MILL
Find MILL in MSQ data
我的数据看起来像
121,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
122,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
123,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
124,736,52,1,5.295,1.000,70.200,3,1.0000,3,1
124,736,52,OIND,70.200,27.641,-np-
125,736,52,1,5.295,1.000,72.175,3,1.0000,3,1
125,736,52,OIND,72.175,308.340,MILL
129,736,52,1,5.295,1.000,70.525,3,1.0000,3,1
129,736,52,OIND,70.525,76.211,MILL
我需要存储所有以“MILL”或“-np-”结尾的数据
然后需要把它放到一个新的MSQ文件中
有什么建议
语言为TCL
类似
set in [open yourfile r]
set out [open newfile w]
while {[gets $in line] >= 0} {
if {[regexp {(?:MILL|-np-)$} $line]} {
puts $out $line
}
}
close $in
close $out
Shawn 出色回答的替代方法:
set in [open yourfile r]
set out [open newfile w]
while {[gets $in line] >= 0} {
switch -glob -- $line {
{*MILL} -
{*-np-} {
puts $out $line
}
}
}
close $in
close $out
全局模式在 string match
documentation 中进行了描述。
我的数据看起来像
121,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
122,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
123,736,52,0,5.295,0.000,70.000,3,1.0000,3,1
124,736,52,1,5.295,1.000,70.200,3,1.0000,3,1
124,736,52,OIND,70.200,27.641,-np-
125,736,52,1,5.295,1.000,72.175,3,1.0000,3,1
125,736,52,OIND,72.175,308.340,MILL
129,736,52,1,5.295,1.000,70.525,3,1.0000,3,1
129,736,52,OIND,70.525,76.211,MILL
我需要存储所有以“MILL”或“-np-”结尾的数据 然后需要把它放到一个新的MSQ文件中
有什么建议 语言为TCL
类似
set in [open yourfile r]
set out [open newfile w]
while {[gets $in line] >= 0} {
if {[regexp {(?:MILL|-np-)$} $line]} {
puts $out $line
}
}
close $in
close $out
Shawn 出色回答的替代方法:
set in [open yourfile r]
set out [open newfile w]
while {[gets $in line] >= 0} {
switch -glob -- $line {
{*MILL} -
{*-np-} {
puts $out $line
}
}
}
close $in
close $out
全局模式在 string match
documentation 中进行了描述。