perl脚本帮助(时间和排序)

时间:2012-03-01 07:33:01

标签: perl

我试图制作一个剧本,但我需要你们的帮助..这将是一个修复.. 从我的脚本和我的脚本中获得的输出作为附件发送。

  1. 我可以将输出视为左对齐吗?
  2. 除此之外,你们可以把空间从“ZAMAN”缩小到“SAHA删除后”*** ALARM“??
  3. 最后一件事想要的是按时间顺序输出?我的意思是书面的顶部必须是最新的日期..?
  4. 我会等你的回答..

    我的剧本


    $dosyaa="LOG.txt";
    $dosya_out="KESIK_SEKTORLER.txt";
    
    open fp1, $dosyaa;
    open fp2, ">$dosya_out" or die "Cannot find $dosya_out for read\n :$!";
    
    print fp2 "              BSC         BCF              ALARM TÜRÜ         ZAMAN                                               SAHA                     ALARM\n";
    
    $count=0;
    $SEG_NUM2=0;
    $BCVI4=0;
    $BTS_ST=0;
    $toplam="";
    $toplam2="";
    $toplam_p="";
    $deneme=0;
    
    foreach $line(<fp1>) {
        chomp($line);
        if (($line =~ /QUAL/)) {$SEG_NUM2=$line};
        if (($line =~ /ALARM/)) {$SEG_NUM3=$line};
        if (($line =~ /ALARM/) or ($line =~ /BCCH MISSING/)) {
            $BTS_ST=$line;
            if (($BTS_ST =~ /BCCH MISSING/) or ($BTS_ST =~ /ALARM/) or ($BTS_ST =~ /QUAL/))  {
                $deneme=$deneme+1
            }
        };
        if (($line =~ /BCCH MISSING/)) {
            if (($BTS_ST =~ /BCCH MISSING/) or ($BTS_ST =~ /ALARM/) or ($BTS_ST =~ /QUAL/))  {
                $BCVI4=$line,
                $toplam= "'".(substr $SEG_NUM2, 06,10)."',";
                if ($toplam ne $toplam_p) {
                    $toplam2=$toplam2.$toplam;
                };
                #if ($toplam==$toplam_p) {$toplam2=$toplam2.",".$toplam};
                print fp2 "$SEG_NUM2 $SEG_NUM3 $BCVI4\n";
                $toplam_p=$toplam;
                $toplam=0,$SEG_NUM2=0,$BTS_ST=0,$BCVI4=0,$BCVI5=0,$count++;
            }
        };
    }
    $toplam2=substr $toplam2,0,-1;
    print fp2 "           KESIK SAHA SAYISI...............$count\n";
    

    我的输入txt

           BCORK01      BCF-0021  BTS-0022    QUAL      2012-02-29  19:21:45.65
    

    * 报警CO11802
       (60624)7767 BCCH MISSING

           BCORK02      BCF-0031  BTS-0022    QUAL      2012-02-29  19:13:45.65
    

    * ALARM CO12802
       (60624)7767 BCCH MISSING

           BCORK03      BCF-0041  BTS-0022    QUAL      2012-02-29  19:11:45.65
    

    * 报警CO14802
       (60624)7767 BCCH MISSING

    我的输出txt

     BSC          BCF          DATE           TIME         SAHA        ALARM
    BCORK01      BCF-0021    2012-02-29     19:11:45.65   CO11801  BCH MISSING   
    BCORK01      BCF-0021    2012-02-29     19:11:45.65   CO11802  BCH MISSSING 
    BCORK01      BCF-0021    2012-02-29     19:11:45.65   CO11802  BCH MISSSING .                                                     
    

2 个答案:

答案 0 :(得分:0)

open fp2, ">$dosya_out" or die "Cannot find $dosya_out for read\n :$!";

您可以首先确保您的错误消息是合理的: - )

答案 1 :(得分:0)

如果我正确地读你的问题,你想要的是:

  1. 从输入中修剪空白
  2. 修正了列宽,因此所有内容都像表格一样排列
  3. 根据日期和时间对输出进行排序时间
  4. 尝试这些更改。我删除了一些代码,以便我更容易阅读:

    $dosyaa="LOG.txt";
    $dosya_out="KESIK_SEKTORLER.txt";
    
    open fp1, $dosyaa;
    open fp2, ">$dosya_out" or die "Cannot find $dosya_out for read\n :$!";
    
    $head_output_format="%-13s%-13s%-15s%-13s%-12s%s\n";
    $body_output_format="%-13s%-12s%-15s%-14s%-9s%s\n";
    printf fp2 $head_output_format, "BSC", "BCF", "DATE", "TIME", "SAHA", "ALARM";
    
    $count=0;
    $SEG_NUM2="";
    $SEG_NUM3="";
    %output_records = ();
    
    foreach $line(<fp1>) {
        chomp($line);
        # Trim whitespace:
        $line =~ s/^\s+//;
        $line =~ s/\s+$//;
    
        if (($line =~ /QUAL/)) {$SEG_NUM2=$line}
        if (($line =~ /ALARM/)) {$SEG_NUM3=$line}
        if (($line =~ /\(/)) {
            ($NUM1, $NUM2, @ALARM_split) = split (" ", $line);
            $ALARM = join (" ", @ALARM_split);
            ($BSC, $BCF, $BTS_ignore, $QUAL_ignore, $DATE, $TIME) = split (/\s+/, $SEG_NUM2);
            ($STAR_ignore, $ALARM_ignore, $SAHA) = split (" ", $SEG_NUM3);
            if ($ALARM eq "BCCH MISSING") {
                push @{$output_records{"$DATE $TIME"}}, sprintf ($body_output_format, $BSC, $BCF, $DATE, $TIME, $SAHA, $ALARM);
            }
            $SEG_NUM2="";
            $SEG_NUM3="";
            $count++;
        }
    }
    
    # sort {$b cmp $a} (reverse sort)
    foreach $date_time (sort {$b cmp $a} keys(%output_records)) {
        foreach $line (@{$output_records{$date_time}}) {
            print fp2 $line;
        }
    }
    
    #print fp2 "           KESIK SAHA SAYISI...............$count\n";