我有一个如下所述的变量
echo $test_output_assign_list
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
我要从此变量中删除重复的行
变量应为
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
我写了下面的小脚本,但没有给出正确的结果
foreach k $test_output_assign_list {
set un [lsort -unique $k]
}
echo $un
{mbist_out.BIST_DATA_FROM_MEM;}
我在这里没有得到正确的结果
答案 0 :(得分:0)
% set test_output_assign_list {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;}
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
% set test [split $lines \n]
{assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;} {assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;}
% set uniques [lsort -unique $lines]
{assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;}
% set unique [lindex $unique 0]
assign BIST_DATA_FROM_MEM = mbist_out.BIST_DATA_FROM_MEM;
答案 1 :(得分:0)
您应该首先将输入分成几行,然后删除重复项。有几种方法可以删除重复项,具体取决于您的意思以及您对哪种排序感兴趣。这是一种使用字典进行重复删除的方法,该方法使用每个唯一项的首次出现的顺序行:
set deduplicated {}
foreach line [split $test_output_assign_list "\n"] {
dict set deduplicated $line 1
}
set deduplicated [join [dict keys $deduplicated] "\n"]