作者ultra400 (阿志)
看板perl
标题[问题] 要怎麽抓取这些字串?
时间Wed Dec 27 17:17:50 2006
请教一下,如果我有以下的文字档:
-A inside-outside -p tcp -m tcp -s 192.168.1.68 --dport 25 -j DROP
-A inside-outside -m mac -s 192.168.1.2 --mac-source 00:0c:76:f5:7e:95 -j
ACCEPT
-A inside-outside -m mac -s 192.168.1.3 --mac-source 00:0e:2e:56:fb:f9 -j
ACCEPT
-A inside-outside -s 192.168.1.48 -j ACCEPT
我想抓出开头有-A inside-outside -s的那一行文字,但是我若写成:
……前面省略………
while (<IN>){
if (/-A inside-outside -s/){
print $_;
}
}
的话,会抓到:
-A inside-outside -p tcp -m tcp -s 192.168.1.68 --dport 25 -j DROP
-A inside-outside -s 192.168.1.48 -j ACCEPT
这二行,但是我只想要第二行,第一行不是我要的结果,
不知各位是否知道要如何改进?
谢谢。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.231.77.218
1F:→ iFEELing: ' ' 12/27 17:34
2F:→ andytzeng:我拿你的 code 直接跑就真的只有哪一行而已呀 12/27 23:45