我有一個perl腳本,用於管理將特定文件格式轉換爲可以稍後管理的csv文件的轉換。Perl - 通過在編寫之前檢查打開的文件中是否存在模式來防止重複
我需要這個腳本能夠防止產生重複行:
#get timetamp
if ((rindex $l,"ZZZZ,") > -1) {
(my $t1, my $t2, my $timestamptmp1, my $timestamptmp2) = split(",",$l);
$timestamp = $timestamptmp2." ".$timestamptmp1;
}
if (((rindex $l,"TOP,") > -1) && (length($timestamp) > 0)) {
(my @top) = split(",",$l);
my $aecrire = $SerialNumber.",".$hostnameT.",".$timestamp.",".$virtual_cpus.",".$logical_cpus.",".$smt_threads.",".$top[1];
my $i = 3;###########################################################################
while ($i <= $#top) {
$aecrire = $aecrire.','.$top[$i];
$i = $i + 1;
}
print (FIC2 $aecrire."\n");
}
我的源文件是FIC1和目標文件FIC2中,uniq的關鍵是$時間戳。
我希望腳本檢查$時間戳FIC1(這是在開始過程中打開)已經存在,如果它不被寫入FIC2排除線。 如果$ timestamp不存在,則按正常方式寫入。
目前,如果重新運行在一個已經進行文件中的腳本,每一行將由時間戳進行排序和複製。
我的目標是能夠定期在文件上運行此腳本而不復制事件。
我很新的Perl中,據我已經看到了這個應該簡單地用看到的,而內變量%來實現,但我還沒有實現它成功...
謝謝非常提前的任何幫助:-)
在Linux上你?您可以將您的輸出傳送到uniq – Jeef