I have a log file that gets continuously populated; let's state its name is logfile.txt. In this log file I want to continuously capture sub strings from a single line that contains other strings on the same line using any bash commands.
This is an example of a line in the log file :
2023-08-31 09:56:39,925 [G_M80T72|utx:0:ffffac17000b:45253299:64ec7753:79cb0e|chnl:LN1_CRYPTO_IN_MQ_REQ_AMP|id:196010175121000000000002134] WARN transaction.GeneralTransactionFailureException - GeneralTransactionFailureException Gateway.Transaction[196010175121000000000000067v1], StatusReason[ProcessingFailed/PayloadIntegrityCheckFailed]
I want to capture the string1 LN1
and string2 CRYPTO_IN_MQ_REQ_AMP
each time the line contains PayloadIntegrityCheckFailed
.
String1 is always preceded by chnl:
'and string2 is always followed by a pipe. The 2 strings are always separated by an underscore (but string2 can also contains underscore)
In my example string1=LN1 but it could be like {any letter characters}LN{any number of digits}
String2 can be made of letters and digits
Once string1 and string2 are captured, I would use them as argument in another command like:
{another_command} string1 string2
Of course only new entries should then be captured and I don't want to scan the full log continuously, only new lines, so I guess a first start would be to tail -f
the file, then use some sed magic along with regular expressions.
Would you have an idea how to proceed?
LN1
andCRYPTO_IN_MQ_REQ_AMP
appear in the same string:LN1_CRYPTO_IN_MQ_REQ_AMP
. Please edit your question and provide the desired output given your example input.