English 中文(简体)
perl 单线, 需要弯曲正数之间的线条
原标题:Perl one-liner, need to chomp lines between regexes
  • 时间:2012-05-25 15:58:06
  •  标签:
  • regex
  • perl

我拥有数千个日志文件,其中贴有日期-时间印章,记录着某些重要事件。 不幸的是,在任何特定日期-时间印章上记录的信息有时会插入新的字符,这样信息就会在几行中传播。 此外,还有其他与我目的无关的信息没有日期-时间印章。

我得到了一个perl一班的, 做的工作是拉出我想要的信息:

perl -ne  print if /^dd:dd:dd.ddd/..!/^dd:dd:dd.ddd/ 

但是,我想删除首行( 包含日期- 时间戳) 之后的新行字符, 以及以下行中的每一行。 但是, 我确实想在以日期- 时间标记开始的下一行之前保留最后一行之后的新行字符 。

我对如何修改我的单行语来完成这一任务一点运气都没有。

最佳回答
perl -ne  if ($inside = /^dd:dd:dd.ddd/..!/^dd:dd:dd.ddd/) {
            chomp unless $inside =~ /E0$/;
            print; } 
问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签