Re: [問題] 用sed合併行
看板RegExp (正規表示式 Regular Expression)作者dryman (dryman)時間12年前 (2013/04/04 06:51)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/2 (看更多)
我覺得用perl寫最簡單
為求易讀性所以我把許多perl magic都拿掉了
熟悉perl的話是可以把它寫得更簡潔的
#!/usr/bin/env perl
use 5.010;
do {
$_ = <STDIN>;
chomp $_; # chomp removes trailing \n
push @arr, $_;
} until ($_ =~ /flag/);
$flag = pop @arr; # the text match flag
$_ = <STDIN>; # obtain the next line after flag
print "$flag $_";
while ($_=<STDIN>) {
print ((shift @arr), " ", $_);
};
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 207.151.231.195
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
0
2
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章