作者dryman (dryman)
看板Linux
標題Re: [問題] awk 一特殊用法
時間Fri Feb 22 04:30:13 2013
#!/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
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 68.181.7.7
推 asadfish:Perl 推一個XDDDDDDDDD 02/22 08:57
→ losepacific:perl -ne 'BEGIN{undef $/}; 02/22 19:44
→ losepacific:print "$1\n" while /(\d+\/\d+[^\d]*ccc)/sg' 檔案 02/22 19:45
→ Sizemore24:Perl 處理這類問題真的看來超強。 02/23 00:31