'Grep lines from the log with matching pattern using Unix command
I have logs in this format. I'm looking to get logs only that has count more than 5000.
Matching pattern should be Count [value greater than 5000]
INFO 56783 Count [5987]
INFO 67988 Count [4986]
INFO 27679 Count [9865]
In the above example, the output should be only
INFO 56783 Count [5987]
I'm using in the following format
sudo cat <path to log> | grep 'Count [5[0-9][0-9][0-9]]'
Any ideas what is missing here
Solution 1:[1]
You can use
awk -F'[][]' '/Count \[[0-9]+]/ && $2 > 5000' file
The field separator matches ] or [ and /Count \[[0-9]+]/ && $2 > 5000 only outputs lines that contain Count [<number>] and where Field 2 is more than 5K.
See the online demo:
#!/bin/bash
s='INFO Count [5987]
INFO Count [4986]
INFO Count [9865] '
awk -F'[][]' '/Count \[[0-9]+]/ && $2 > 5000' <<< "$s"
Output:
INFO Count [5987]
INFO Count [9865]
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 |
