jeudi 13 juillet 2017

How to read in a text file and check for similar pattern

I have a text file with the following format :

170705 232049 ucart :** Message received with rcode 0x85, length 62
170705 232049 ucart :CartScanned: cart 1076, dt 0, SC 6, status 0x0, codes 2
170705 232049 ucart :CodeConvert: cart 1076, dt 0, IRES_scan
170705 232049 ucart :IRES_scan cart 1076, dt 0, req 2: 119, 0: 65535, 0: 0, 0: 0
170705 232049 xconv :convConvert: (0x66), org. rcode 0x85, next 0, cart 1076
170705 232049 ucart :stactExe: cart 1076, dt 0, event 0x02, statec. from 2 to 3
170705 232049 xconv :DoConv: barcode <>, pcode <>, sortflags 0x0, product 0, spec.sort CONV_OK(0), vehicId -1, rec.reason 0, recmode 0
170705 232049 xconv :crossGetNextFromQueue: cart 1076, infeed 27, barcode "PBSF7223594002", next is "PBSF7223594002"
170705 232049 xconv :DoConv: res 0, barcode <PBSF7223594002>, pcode <CT5 3QS>, prod 2 (0x0), depot <O22409>, vehicId -1, sortflags 0x23, tableflags 0x1a, wdg 60.1 16383.3, recmode 0
170705 232049 ucart :** Message received with rcode 0x66, length 574
170705 232049 ucart :Converted: cart 1076, dt 0, ccode =          res = 0x00, rescan 0
170705 232049 ucart :Code converted: cart 1076, dt 0, SC cnt 0, SC 6, inf 27, res 0x00
170705 232049 ucart :usrtiltSendTiltCmd: ires 1, cart 1076, dt 0, conv.res CONV_OK(0), tilt.reason CONV_OK(0), alt[0] 60.1, alt[1] 1638

It has a lot of data around parcels, what I need to do it read the data in line by line and check the a specific item relating to the bar code

barcode <PBTS1435406003>

I then need to store this then read in the next line and keep checking to see if it matches BUT if another barcode is read then I need to store that and again check if a match happens as I continue to read the file.

Is there a way to do this in an array or something.

Essentially I need to find the start and end of each barcode.

Thanks

Phil

Aucun commentaire:

Enregistrer un commentaire