awk 一特殊用法 - Linux

Table of Contents

#!/usr/bin/env perl
# It reads from STDIN

while ($string=<STDIN>) {
# push $string to @lines until reach numbers
push @lines, $string and next unless $string =~ /^\d+/;
# print @lines if last element is 'ccc'
print @lines if $lines[$#lines] =~ /ccc/;
# reset @lines with first element as numbers
@lines = ($string);
}

# handle end of file
print @lines if $lines[$#lines] =~ /ccc/;



Perl 處理文字真的超強,不考慮學一下嗎?XD

--

All Comments

Steve avatarSteve2013-02-26
Perl 推一個XDDDDDDDDD
James avatarJames2013-03-02
perl -ne 'BEGIN{undef $/};
Puput avatarPuput2013-03-06
print "$1\n" while /(\d+\/\d+[^\d]*ccc)/sg' 檔案
Andy avatarAndy2013-03-06
Perl 處理這類問題真的看來超強。