set line {
Aug 07 18:12:00 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName *.daily
motion.com. Flow: 0x87078500.
Aug 07 18:12:00 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName DigiCer
t High Assurance CA-3. Flow: 0x87078500.
}
if {![regexp {CommonName ([a-zA-Z0-9\.]*) Flow:} $line junk one]} {
error "invalid parsing"
}
puts "$one"
如何grep“CommonName .... Flow:”之间的任何内容。我写过上面的剧本。但它不起作用。我无法在$ line变量中处理“* .daily和motion”之间的空格。
输出应该是:*。dailymotion.com。
DigiCert High Assurance CA-3。
请帮助我解决你的想法。
谢谢,
Balu P。
答案 0 :(得分:1)
你可以简单地使用.
这是一个通配符来匹配任何字符,除非你通过添加?
使其变得懒惰:
[regexp {CommonName (.*?) Flow:} $line - one]
除此之外,您的行分为多行,因此您可能需要替换换行符:
regsub -all {[\r\n]} $one "" one
会在没有换行符的情况下为您提供变量$one
。
set line {
Aug 07 18:12:00 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName *.daily
motion.com. Flow: 0x87078500.
Aug 07 18:12:00 2014: %DATAPLANE-5-: Unrecognized Server Cert CommonName DigiCer
t High Assurance CA-3. Flow: 0x87078500.
}
if {![regexp {CommonName (.*?) Flow:} $line - one]} {
error "invalid parsing"
}
regsub -all {[\r\n]} $one "" one
puts "$one"