1

我有一个看起来像这样的文件:

sort=SIZE:NumberDecreasing
FieldText=(((EQUAL{226742}:LocationId)) AND ()) 

FieldText=(((EQUAL{226742}:LocationId)) AND ((EQUAL{1}:LOD AND NOTEQUAL{1}:SCR AND EMPTY{}:RPDCITYID AND NOTEQUAL{1}:Industrial))) 

FieldText=( NOT EQUAL{1}:ISSCHEME AND EQUAL{215629}:LocationId) 

sort=DEALDATE:decreasing

从这个我想要一个冒号之前的单词,如果有 {} 括号,在那些之前也是一个冒号,然后是冒号之后的单词。理想情况下,这些应该是文件中唯一剩下的东西,每个都在自己的新行上。

输出将如下所示:

SIZE:NumberDecreasing
EQUAL:LocationId 
EQUAL:LocationId
EQUAL:LOD
NOTEQUAL:SCR
EMPTY:RPDCITYID
NOTEQUAL:Industrial
EQUAL:ISSCHEME
EQUAL:LocationId    
DEALDATE:decreasing

到目前为止我最接近的是:查找:^。?+ {[0-9] }:([a-zA-Z]+) 替换为:...\1:\2...

打算运行它几次,然后用 \n 替换 ... 然后我可以删除多个换行符。

上下文:这是我正在执行的日志分析,我已经删除了日期戳,并将查询元素减少到排序和 FieldText 参数

我没有常规的 UNIX 工具 - 我在 Windows 环境中工作

原始日志如下所示:

03/11/2011 16:25:44 [9] ACTION=Query&summary=Context&print=none&printFields=DISPLAYNAME%2CRECORDTYPE%2CSTREET%2CTOWN%2CCOUNTY%2CPOSTCODE%2CLATITUDE%2CLONGITUDE&DatabaseMatch=Autocomplete&sort=RECORDTYPE%3Areversealphabetical%2BDRETITLE%3Aincreasing&maxresults=200&FieldText=%28WILD%7Bbournemou%2A%7D%3ADisplayName%20NOT%20MATCH%7BScheme%7D%3ARecordType%29 (10.55.81.151)
03/11/2011 16:25:45 [9] Returning 23 matches
03/11/2011 16:25:45 [9] Query complete
03/11/2011 16:25:46 [8] ACTION=GetQueryTagValues&documentCount=True&databaseMatch=Deal&minScore=70&weighfieldtext=false&FieldName=TotalSizeSizeInSquareMetres%2CAnnualRental%2CDealType%2CYield&start=1&FieldText=%28MATCH%7BBournemouth%7D%3ATown%29 (10.55.81.151)
03/11/2011 16:25:46 [12] ACTION=Query&databaseMatch=Deal&maxResults=50&minScore=70&sort=DEALDATE%3Adecreasing&weighfieldtext=false&totalResults=true&PrintFields=LocationId%2CLatitude%2CLongitude%2CDealId%2CFloorOrUnitNumber%2CAddressAlias%2A%2CEGAddressAliasID%2COriginalBuildingName%2CSubBuilding%2CBuildingName%2CBuildingNumber%2CDependentStreet%2CStreet%2CDependentLocality%2CLocality%2CTown%2CCounty%2CPostcode%2CSchemeName%2CBuildingId%2CFullAddress%2CDealType%2CDealDate%2CSalesPrice%2CYield%2CRent%2CTotalSizeSizeInSquareMetres%2CMappingPropertyUsetype&start=1&FieldText=%28MATCH%7BBournemouth%7D%3ATown%29 (10.55.81.151)
03/11/2011 16:25:46 [8] GetQueryTagValues complete
03/11/2011 16:25:47 [12] Returning 50 matches
03/11/2011 16:25:47 [12] Query complete
03/11/2011 16:25:51 [13] ACTION=Query&print=all&databaseMatch=locationidsearch&sort=RELEVANCE%2BPOSTCODE%3Aincreasing&maxResults=10&start=1&totalResults=true&minscore=70&weighfieldtext=false&FieldText=%28%20NOT%20LESS%7B50%7D%3AOFFICE%5FPERCENT%20AND%20EXISTS%7B%7D%3AOFFICE%5FPERCENT%20NOT%20EQUAL%7B1%7D%3AISSCHEME%29&Text=%28Brazennose%3AFullAddress%2BAND%2BHouse%3AFullAddress%29&synonym=True (10.55.81.151)
03/11/2011 16:25:51 [13] Returning 3 matches
03/11/2011 16:25:51 [13] Query complete

整个练习的目的是找出正在查询和排序的字段(以及我们如何查询/排序它们)——为此,输出也可以是不同的——尽管这不是必需的。

4

1 回答 1

1

下面的 Perl 程序是完整的,并且在源代码中包含了您的示例数据。它会产生您描述的输出,包括NOT EQUAL{1}:ISSCHEME由于EQUAL:ISSCHEME中间空间而报告。

use strict;
use warnings;

while (<DATA>) {
  print "$1:$2\n" while /(\w+)  (?: \{\d*\} )? : (\w+)/xg;
}

__DATA__
sort=SIZE:NumberDecreasing
FieldText=(((EQUAL{226742}:LocationId)) AND ()) 

FieldText=(((EQUAL{226742}:LocationId)) AND ((EQUAL{1}:LOD AND NOTEQUAL{1}:SCR AND EMPTY{}:RPDCITYID AND NOTEQUAL{1}:Industrial))) 

FieldText=( NOT EQUAL{1}:ISSCHEME AND EQUAL{215629}:LocationId) 

sort=DEALDATE:decreasing

输出

  SIZE:NumberDecreasing
  EQUAL:LocationId
  EQUAL:LocationId
  EQUAL:LOD
  NOTEQUAL:SCR
  EMPTY:RPDCITYID
  NOTEQUAL:Industrial
  EQUAL:ISSCHEME
  EQUAL:LocationId
  DEALDATE:decreasing
于 2011-11-11T13:00:58.520 回答