如何避免在附加的TCL脚本中打印不需要的行

时间:2014-08-08 08:32:01

标签: regex tcl

请查看以下链接中的代码:昨天Jerry为我的要求撰写:

http://ideone.com/CBz6WG

当我使用$ line变量时(在该脚本中),它正在工作。当我用以下行替换$line内容时,regexp会产生一些不需要的输出。

set line {

test-443670#show logging


Logging module: enabled

    Aggregation time: disabled

    Console logging: level debugging

    Monitor logging: disabled

    Buffered logging: level debugging

    Syslog logging: level debugging

        Facility: local7


Log Buffer (5003 bytes):



Aug 08 15:44:02 2014: %DATAPLANE-5-: Searching rname(TYPE_A) qweplost.com in dns

_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Unrecognized HTTP URL www.google-analytics.

com. Flow: 0x8707e380.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Unrecognized HTTP URL www.google-analytics.

com. Flow: 0x8707e380.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) ocsp.verisign.net i

n dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:58 2014: %DATAPLANE-5-: Searching rname(TYPE_A) www-google-analytic

s.l.google.com in dns_hash_table.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Searching rname(TYPE_AAAA) www-google-analy

tics.l.google.com in dns_hash_table.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized HTTP URL www.babelgum.com. Flo

w: 0x8706ed80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName RapidSS

L CA. Flow: 0x87073e80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName GeoTrus

t Global CA. Flow: 0x87073e80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName *.elite

modellook.com. Flow: 0x87073e80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName RapidSS

L CA. Flow: 0x87073e80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized HTTP URL www.babelgum.com. Flo

w: 0x8706ed80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized Client Hello ServerName ?www.b

abelgum.com. Flow: 0x87073e80. len_analyzed: 183.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Unrecognized HTTP URL www.babelgum.com. Flo

w: 0x8706ed80.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Searching rname(TYPE_A) elite-862037136.eu-

west-1.elb.amazonaws.com in dns_hash_table.

Aug 08 15:43:57 2014: %DATAPLANE-5-: Searching rname(TYPE_A) elite-862037136.eu-

west-1.elb.amazonaws.com in dns_hash_table.

Aug 08 15:43:53 2014: ap622-443670 : %SYSTEM-6-CONFIG_REVISION: Configuration re

vision updated to 36 from 35

Aug 08 15:43:53 2014: ap622-443670 : %SYSTEM-6-CONFIG_REVISION: Configuration re

vision updated to 35 from 34

Aug 08 15:43:53 2014: ap622-443670 : %SYSTEM-6-CONFIG_COMMIT: Configuration comm

it by user 'admin' (mapsh) from '127.0.0.1'

Aug 08 15:43:48 2014: ap622-443670 : %SYSTEM-5-LOGIN: Successfully logged in use

r 'admin' with privilege 'superuser' from 'pts/0'

Aug 08 15:43:48 2014: %AUTH-6-INFO: login[5597]: user 'admin' on 'pts/0' logged

in

Aug 08 15:43:42 2014: %DATAPLANE-5-: Searching rname(TYPE_A) qweplost.com in dns

_hash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:28 2014: %DATAPLANE-5-: Searching rname(TYPE_A) google.com in dns_h

ash_table.

Aug 08 15:43:11 2014: %DATAPLANE-5-: Searching rname(TYPE_A) zeplost.com in dns_

hash_table.

Aug 08 15:42:50 2014: %DATAPLANE-5-: Searching rname(TYPE_A) zeplost.com in dns_

hash_table.

Aug 08 15:42:20 2014: %DATAPLANE-5-: Searching rname(TYPE_A) replost.com in dns_

hash_table.

Aug 08 15:41:59 2014: %DATAPLANE-5-: Searching rname(TYPE_A) replost.com in dns_

hash_table.

Aug 08 15:39:46 2014: ap622-443670 : %SYSTEM-6-LOGOUT: Logged out user 'admin' w

ith privilege 'superuser' from '127.0.0.1'

}

重现问题的步骤:

  1. 运行“http://ideone.com/CBz6WG。”中的脚本。您将看到清除输出,每个输出都用逗号分隔。
  2. 现在将$ line的内容更改为上面给出的内容。
  3. 它会给出一些不需要的线条。

    我努力解决这个问题,但我无法解决这个问题。

    你们中的任何人,请帮帮我吗?

1 个答案:

答案 0 :(得分:1)

我不认为让正则表达式适应这种情况很容易,因为这是输入的固有问题。我建议先从输入中删除所有换行符:

regsub -all {[\r\n]} $line "" line
foreach {whole type payload} {...}

ideone demo