我正在研究grep和zgrep文件

时间:2015-10-28 21:33:47

标签: regex perl grep

我是regex和Perl的新手。如果从csh:

移植时这是Perl中的正确语法,请你帮忙吗?

CSH:

set shipDate = `zgrep "::RUNTIME:: SHIP end time/date:" $shipLogFile | sed 's/.*time\/date\://g' | sed 's#"##g'`

的Perl:

  my $wardSwizzled     = "$WARD/ship/ip/${DBB1}/swizzled";
  my $wardpds          = "$wardSwizzled/pds/logs/${DBB1}";
  my $accept10SumFile  = "$wardpds.ccdo_accept10.iss.log.sum";
  my $wardReview       = "$wardSwizzled/review/${DBB1}";
  my $reviewCloseFile  = "$wardReview.close";
  my $wardship         = "$WARD/ship/log/${DBB1}";    
  my $shipLogFile      = "$wardship.ship.log";

  my @shipDate;
  open my $fh, '<', $shipLogFile or die "Can't open $shipLogFile: $!";
  while (<$fh>)
  {
  next if (!m/::RUNTIME:: SHIP end time/date:/);
  push @shipDate, $.;
  }
  close $fh;

1 个答案:

答案 0 :(得分:0)

  

我不确定这条线是否正确&#34;&#34; next if (!m/::RUNTIME:: SHIP end time/date:/);&#34;&#34;因为我在我的短信和{34; date:/&#34;以不同的颜色显示。所以我猜测语法错了。

是的,你是对的(快速测试就会告诉你)。由于您选择了/作为分隔符,因此它标记了模式的结束。以下是两种最常用的解决方案:

next if !/::RUNTIME:: SHIP end time\/date:/;   # Escape
next if !m{::RUNTIME:: SHIP end time/date:};   # Alternate delimiter.