2016-09-17 15 views
-2

私はテキスト形式の結果を私に提供するPerlスクリプトを持っています。 このテキストから一部の情報のみを印刷する必要があります。 Perlで印刷するための開始パターンと終了パターンを定義するにはどうすればよいですか?Perlのマッチパターンからの印刷

+0

である私の結果:現在のポート制限無制限のプロトコルスタックIPV4のIPアドレス(適用)QOS-ポリシングポリシーレート - 2M-in(適用)qos-metering-policy rate-2M-out(適用)[sCLIPS] Redback(config-ctx)#そしてqos-policing-policy rate-2M-in(適用)計量政策金利-2Mアウト(適用) – wael

+1

何か試しましたか? – Shades

+0

あなたの質問を編集し、あなたのコメントから情報を挿入してください。また、あなたが望む出力を教えてください。 –

答えて

0

あなたが何を求めているのか正確にはわかりませんが、試してみます。 プレーンテキストを含むファイルをストリーミングする場合、「qos-policing-policy rate-2M-in(適用)qos-metering-policy rate-2M-out(適用)」の行だけを除外したいとします。そして、だけそれらの単語を抽出し、その後、次のコードは、スクリプトを書くためにどのようなアイデアを与えることができる:

のPerlプログラム:

#!/usr/bin/perl 
# test.pl 

use strict; 
use warnings; 

while(<>) { 
     my @a = m/(qos-\S+\s+\S+\s+\(applied\))/g; 
     for my $i (@a) { 
      print "$i "; 
     } 
     print "\n" if (@a); 
} 

これはあなたの開始パターンと終了パターンのようになります。

m/qos-\S+\s+\S+\s+\(applied\)/g 

開始位置:

qos- 

と終わりである:

\(applied\) 

"G" オプションが入ってくるライン上のグローバルマッチのために使用されているが。

入力:

> cat textFile.txt 
Current port-limit unlimited Protocol Stack IPV4 ip address (applied) qos-policing-policy rate-2M-in (applied) qos-metering-policy rate-2M-out (applied) [sCLIPS]Redback(config-ctx) 
line number two is here 
Stack IPV4 ip address (applied) qos-policing-policy rate-299M-in (applied) qos-metering-policy 

出力:ここ

> cat textFile.txt | perl ./test.pl 
qos-policing-policy rate-2M-in (applied) qos-metering-policy rate-2M-out (applied) 
qos-policing-policy rate-299M-in (applied) 
+0

私のテキスト・ファイルです:セッション状態アップ サーキット3/3 VLAN-ID 1523 内部回路3/3:511:63:31/1/2/20600 インターフェースがバインドstaticip81 現在のポート制限無制限 プロトコルスタックIPV4 qos-policing-policy rate-2M-in(適用済み) qos-metering-policy rate-2M-out(適用済み) [sCLIPS] Redback(config-ctx)# – wael

+0

と私はqos-policing-policy rate -2M-in(適用)qos-metering-policy rate-2M-out(適用) – wael

+0

あなたの解決策を試しましたが、うまくいきません:( – wael

関連する問題