亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3260 | 回復(fù): 5
打印 上一主題 下一主題

只打印文件中連續(xù)三行都不為空的內(nèi)容,求思路 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-11-12 17:46 |只看該作者 |倒序?yàn)g覽
例如,有一個(gè)文件內(nèi)容為:


random line content
random line content

random line content
random line content



random line content
random line content
random line content

random line content
random line content
random line content


random line content為隨機(jī)任意內(nèi)容,每行都不一樣;

只想打印連續(xù)三行都不為空行的內(nèi)容,
也就是
random line content
random line content
random line content

random line content
random line content
random line content

求思路,謝謝

論壇徽章:
1
羊年新春福章
日期:2015-04-28 20:40:58
2 [報(bào)告]
發(fā)表于 2014-11-12 19:04 |只看該作者
試試~
  1. #!/usr/bin/perl -w
  2. $/ = "\n\n";
  3. while (<DATA>){
  4. my @a = split /\n/,$_;
  5. print $_ if $#a == 2;
  6. }


  7. __DATA__
  8. random line content
  9. random line content

  10. random line content
  11. random line content



  12. random line content
  13. random line content
  14. random line content

  15. random line content
  16. random line content
  17. random line content
復(fù)制代碼
回復(fù) 1# b4and5


   

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
3 [報(bào)告]
發(fā)表于 2014-11-12 22:28 |只看該作者
while (<DATA>){
    chomp;
    if(/^$/){
        @keep=();
    }
    else{
        push @keep,$_;
        if(@keep+0 ==3){
            print (join "\n",@keep);
            print "\n\n";
            @keep = ();
        }
    }
}

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [報(bào)告]
發(fā)表于 2014-11-12 23:30 |只看該作者
回復(fù) 1# b4and5

$ cat 3line.pl
use strict;
use warnings;

my $sCnt = 0;
my $sStr = "";
while (<DATA>){
  chomp;
  if(/^\s*$/){
    $sCnt = 0;
    $sStr = "";
    next;
  }
  $sStr .= "$_\n";
  if(++$sCnt >=3){
    print "$sStr";
    $sStr = "";
  }      
}

__DATA__
random line content 1
random line content 2

random line content 4
random line content 5



random line content 9
random line content 10
random line content 11

random line content 13
random line content 14
random line content 15
random line content 16

$ perl 3line.pl
random line content 9
random line content 10
random line content 11
random line content 13
random line content 14
random line content 15
random line content 16

   

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2014-11-16 11:53 |只看該作者
Administrator@SWYWXQ1DHSU3MJ6 ~/perl
$ perl -e 'BEGIN{$/=undef;} $_ = <>; @_ = /((??>.+)\n){3})/g; print @_'  testfile
random line content1
random line content2
random line content3
random line contentaaa1
random line contentaaa2
random line contentaaa3
random line contentbbb4
random line contentbbb5
random line contentbbb6

Administrator@SWYWXQ1DHSU3MJ6 ~/perl
$ cat testfile
random line content1
random line content2
random line content3

random line content
random line content



random line contentaaa1
random line contentaaa2
random line contentaaa3

random line contentbbb4
random line contentbbb5
random line contentbbb6

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2014-11-16 11:56 |只看該作者
  1. perl -e 'BEGIN{$/=undef;} $_ = <>; @_ = /((?:(?>.+)\n){3})/g; print @_'  testfile
復(fù)制代碼
我x,居然變成笑臉了!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP