How to find first occurrence of string in log file, set T/F value as variable, and record changes that occur
1
vote
3
answers
740
views
I'm not sure how to title this, but here's what I've got:
A file with text like:
[10:03:43] 10:03:35 22JUN22 ConUP CW1B1 T CW1B3 T CW1B5 T CW1B7 T
[10:03:44] CW2B1 T CW2B4 T CW2B5 T CW2B7 T
[10:03:44] CW3B1 T CW3B4 T CW3B5 T CW4B4 T
[10:03:44] CW4B8 T CW5B4 T CW5B8 T CW6B4 T
[10:03:44] CW6B8 T CW7B8 T CW8B4 T CW8B8 T
[10:03:44] CW9B4 T CW9B8 T CW10B4 T CW10B8 T
[10:03:44] CW11B4 T CW11B8 T CW12B4 T CW12B8 T
[10:04:16] 10:04:28 22JUN22 ConUP CW1B1 T CW1B3 T CW1B5 T CW1B7 T
[10:04:36] CW2B1 F CW2B3 F CW2B5 F CW2B7 F
[10:04:36] CW3B1 T CW3B4 T CW3B5 T CW4B4 T
[10:04:36] CW4B8 T CW5B4 T CW5B8 T CW6B4 T
[10:04:37] CW6B8 T CW7B8 T CW8B4 T CW8B8 T
[10:04:37] CW9B4 T CW9B8 T CW10B4 T CW10B8 T
[10:04:37] CW11B4 T CW11B8 T CW12B4 T CW12B8 T
Then the actual file is full of stuff like that with the True and False values changing.
Whenever a have an entry of True, and it hasn't changed since the last entry, I wanted to remove that entry, only keeping the entry if the value has changed to False (or from False to True).
My thought is I need to find the first occurrence of a string (CW1B1 for example) then store the T or F value that follows it as a variable. Then check for the next occurrence, and compare the T/F value, if it's the same, the use cut or send to remove the entry, and then go look for the next. If it's value has changed, just ignore it and move on.
Expected output:
[10:03:43] 10:03:35 22JUN22 ConUP CW1B1 T CW1B3 T CW1B5 T CW1B7 T
[10:03:44] CW2B1 T CW2B4 T CW2B5 T CW2B7 T
[10:03:44] CW3B1 T CW3B4 T CW3B5 T CW4B4 T
[10:03:44] CW4B8 T CW5B4 T CW5B8 T CW6B4 T
[10:03:44] CW6B8 T CW7B8 T CW8B4 T CW8B8 T
[10:03:44] CW9B4 T CW9B8 T CW10B4 T CW10B8 T
[10:03:44] CW11B4 T CW11B8 T CW12B4 T CW12B8 T
[10:04:16] 10:04:28 22JUN22 ConUP
[10:04:36] CW2B1 F CW2B3 F CW2B5 F CW2B7 F
[10:04:36]
[10:04:36]
[10:04:37]
[10:04:37]
[10:04:37]
Maybe there is a better way to do it, but I still need help coming up with the framework, then I can go and create all the possible variables required in the script.
Asked by ditch
(9 rep)
Jun 21, 2022, 06:18 PM
Last activity: Jul 1, 2022, 10:38 AM
Last activity: Jul 1, 2022, 10:38 AM