'Linux: grepping last characters from file

I have to perform a grep through a log file. The grep needs to include two expressions:

  1. In the log "bpm-activation-fibra-up-kjar:0.0.2"
  2. And it needs to end with ";1"

Here's an example log:

47141;212a386d-00bd-4d73-8a81-ed98d2fd82a6@pam@fibra-up-bpm-manager-activation;NULL;NULL;bpm-activation-fibra-up-kjar:0.0.2;pamadmin;NULL;-1;it.activationUpProcess;47870;activationUpProcess;1;1.0;0;NULL;24/07/2021 10:51;1

While the first grep works well, the second one does not work:

grep "bpm-activation-fibra-up-kjar:0.0.2" data-1647411104037.csv | grep ".*;1$"

No data is returned.
Can you recommend how to perform the second grep on the last two characters?



Solution 1:[1]

I didn't test this, but I see two possible issues in your expressions:

  • The presence of colons and other possibly wildcard characters in the first expression. (Proposal: use fgrep, which doesn't care about wildcards)
  • The characters, preceding the ;1 in the second expression. (Proposal: drop the .*)

So I would opt for:

fgrep "bpm-activation-fibra-up-kjar:0.0.2" data-1647411104037.csv | grep ";1$"

Solution 2:[2]

Suggesting awk script:

  awk '/bpm-activation-fibra-up-kjar:0.0.2/ && /;1$/ 1' data-1647411104037.csv

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dominique
Solution 2 Dudi Boy