GAWK - 寻找相应的行动

时间:2017-08-30 08:32:39

标签: gawk

我有一个大量的顺序添加的数据行,这些数据与通过系统的parcel有关,这个文件会在每个动作发生时添加到全天构建。我需要做的是检查文件说每分钟并检查尚未到达滑槽的物品,即没有" DISCHARGE_VERIFIED"。下面的示例是一个完整的记录,但这可以在整个文件中传播,因为同时处理了数千个项目。

loadingWords()

一旦物品进入它的滑槽,它就被表示为" DISCHARGE_VERIFIED"所以我需要能够退出日志文件,那些行有" itemId"但没有相应的" DISCHARGE_VERIFIED"在那个时间点并显示它正在前进的滑槽,该滑槽保持在元素" CmcdestinationId =< 121:FLY425>"中的行#34; ITEM_INDUCTED"见下文

170209 043314 0887 DE(N) ItemHandler.ItemLog event=<ITEM_AT_INDUCTION>, *********************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: ProjectIdle>, inductionId=<3: IU04>, position=<sorter#0.induction#3: IU04>, itemRevisionNumber=<0> ##[
170209 043314 0888 DE(N) ItemHandler.ItemLog event=<SET_ITEM_ID>, ***************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: ProjectIdle>, itemRevisionNumber=<0> ##[
170209 043317 0314 DE(N) ItemHandler.ItemLog event=<SCANNER_RESULT>, ************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodeCount=<3>, barcodes=<[ProxyWrapperBarcode(barcode=<JJD014600004054211864>, type=<C0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<1910456693>, type=<A0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<2LAU2000+52000000>, type=<C0>, result=<OK>, ccType=<>)]>, codeSource=<ohscan>, scannerId=<4001: IU04-SCAN02>, scannerStatus=<0>, position=<sorter#0.scanner#4001: IU04-SCAN02>, itemRevisionNumber=<2> ##[
170209 043317 0315 DE(N) ItemHandler.ItemLog event=<DESTINATION_REQUEST>, *******************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodes=<[ProxyWrapperBarcode(barcode=<JJD014600004054211864>, type=<C0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<1910456693>, type=<A0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<2LAU2000+52000000>, type=<C0>, result=<OK>, ccType=<>)]>, ccReason=<SCANNER_DATA_ADDED>, PreviousccResult=<>, sortSchemeId=<-1>, sortSchemeName=<>, logicalDestination=<>, BatchCountItem=<true>, collectionId=<-1>, goodsId=<>, position=<sorter#0.scanner#4001: IU04-SCAN02>, dynamicDataCount=<0>, dynamicData=<{}>, carrierId=<159>, carrierCount=<-1>, itemRevisionNumber=<2> ##[
170209 043317 0322 DE(N) ItemHandler.ItemLog event=<DESTINATION_REPLY>, *********************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, ccReason=<SCANNER_DATA_ADDED>, PendingccResult=<OK>, Pendingstrategy=<notSpecified>, PendingchuteGroup=<[3000]: Parked0>, PendingNotChutedestinationId=<-1>, PendingsortSchemeId=<-1>, PendingsortSchemeName=<>, PendinglogicalDestination=<>, PendinggoodsId=<>, PendingBatchCountItem=<true>, PendingcollectionId=<-1>, position=<sorter#0.scanner#4001: IU04-SCAN02>, dynamicDataCount=<0>, dynamicData=<{}>, itemRevisionNumber=<4> ##[
170209 043317 0322 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM>, *************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, PendingchuteGroup=<[3000]: Parked0>, Pendingstrategy=<notSpecified>, CscdestinationId=<-1: UnDef>, CmcdestinationId=<-1: UnDef>, position=<sorter#0.scanner#4001: IU04-SCAN02>, itemRevisionNumber=<4> ##[
170209 043317 0484 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM_REPLY>, *******************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4001: IU04-SCAN02>, chuteListStartPoint=<-1>, itemRevisionNumber=<6> ##[
170209 043317 0486 DE(N) ItemHandler.ItemLog event=<RECONVERT>, *****************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForData>, CscdestinationId=<3000: Parked0>, chuteGroup=<[3000]: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4001: IU04-SCAN02>, chuteListStartPoint=<-1>, itemRevisionNumber=<7> ##[
170209 043317 0486 DE(N) ItemHandler.ItemLog event=<DESTINATION_REQUEST>, *******************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForData>, barcodes=<[ProxyWrapperBarcode(barcode=<JJD014600004054211864>, type=<C0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<1910456693>, type=<A0>, result=<OK>, ccType=<>), ProxyWrapperBarcode(barcode=<2LAU2000+52000000>, type=<C0>, result=<OK>, ccType=<>)]>, ccReason=<SCANNER_DATA_ADDED>, PreviousccResult=<OK>, sortSchemeId=<-1>, sortSchemeName=<>, logicalDestination=<>, BatchCountItem=<true>, collectionId=<-1>, goodsId=<>, position=<sorter#0.scanner#4001: IU04-SCAN02>, dynamicDataCount=<0>, dynamicData=<{}>, carrierId=<159>, carrierCount=<-1>, itemRevisionNumber=<7> ##[
170209 043317 0492 DE(N) ItemHandler.ItemLog event=<DESTINATION_REPLY>, *********************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, ccReason=<SCANNER_DATA_ADDED>, PendingccResult=<OK>, Pendingstrategy=<priority>, PendingchuteGroup=<[121]: FLY425>, PendingNotChutedestinationId=<-1>, PendingsortSchemeId=<-1>, PendingsortSchemeName=<>, PendinglogicalDestination=<FLY425>, PendinggoodsId=<>, PendingBatchCountItem=<true>, PendingcollectionId=<-1>, position=<sorter#0.scanner#4001: IU04-SCAN02>, dynamicDataCount=<0>, dynamicData=<{}>, itemRevisionNumber=<9> ##[
170209 043317 0492 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM>, *************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, PendingchuteGroup=<[121]: FLY425>, Pendingstrategy=<priority>, CscdestinationId=<3000: Parked0>, CmcdestinationId=<3000: Parked0>, position=<sorter#0.scanner#4001: IU04-SCAN02>, itemRevisionNumber=<9> ##[
170209 043317 0666 DE(N) ItemHandler.ItemLog event=<REDIRECT_ITEM_REPLY>, *******************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: WaitForDestination>, CscdestinationId=<121: FLY425>, chuteGroup=<[121]: FLY425>, CmcdestinationId=<121: FLY425>, position=<sorter#0.scanner#4001: IU04-SCAN02>, chuteListStartPoint=<121>, itemRevisionNumber=<11> ##[
170209 043317 0667 DE(N) ItemHandler.ItemLog event=<ITEM_INDUCTED>, *************************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, inductionId=<3: IU04>, inductionMode=<SCANNER>, inductStatus=<NORMAL_ITEM>, carrierId=<159>, carrierCount=<1>, CmcdestinationId=<121: FLY425>, position=<sorter#0: MS01>, itemRevisionNumber=<12> ##[
170209 043327 0379 DE(N) ItemHandler.ItemLog event=<ITEM_DISCHARGED>, ***********************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: ProjectHeadingForChute>, CscdestinationId=<121: FLY425>, chuteGroup=<[121]: FLY425>, CmcdestinationId=<121: FLY425>, ccResult=<OK>, sortSchemeId=<-1>, logicalDestination=<FLY425>, goodsId=<>, carrierId=<159>, length=<-1 mm>, width=<-1 mm>, height=<-1 mm>, volume=<-1 mm3>, position=<sorter#0.chute#121: FLY425>, itemRevisionNumber=<13> ##[
170209 043339 0765 DE(N) ItemHandler.ItemLog event=<DISCHARGE_VERIFIED>, ********************, itemId=<12562305>, globalId=<12562305>, cmcIndex=<750>, sorter=<0: MS01>, state=<CSC: ProjectWaitForVerification>, CscdestinationId=<121: FLY425>, chuteGroup=<[121]: FLY425>, CmcdestinationId=<121: FLY425>, position=<sorter#0.chute#121: FLY425>, itemRevisionNumber=<14> ##[

我在使用gawk的Windows机器上执行此操作,因此具有所有常见的引用问题。

任何帮助将不胜感激

由于

菲尔

1 个答案:

答案 0 :(得分:1)

我想我有一个工作脚本。例如,将其保存为 inducted.awk ,这样就可以跳过您描述的所有Windows引用问题。

inducted.awk:

/ITEM_INDUCTED/ {
    match($0, /itemId=<([^>]+)>/, ary1)
    match($0, /CmcdestinationId=<([^>]+)>/, ary2)
    dest[ary1[1]] = ary2[1]
}

/DISCHARGE_VERIFIED/ {
    match($0, /itemId=<([^>]+)>/, ary1)
    delete dest[ary1[1]]
}

END {
    for (id in dest) {
        print id " -- " dest[id]
    }
}

所以基本上,当找到带有ITEM_INDUCTED的行时,它会将itemid和destination添加到数组中。

当一行有DISCHARGED_VERIFIED时,该信息将从数组中删除。

在脚本结束时,剩余的导入但未排出的ID将打印出目的地。

执行它:

gawk -f .\inducted.awk large_log_file

如果awk文件与large_log_file不在同一文件夹中,请指定它的完整路径。