In my logfile I need to count a unique piece of string. This string is many times in the logfile.
The unique parts (bold within this example string, the capital NNNN is a number but not known how many digits and the capital CCC are optional filled with a number or character but also not known how many characters) it is always separated by underscores:
"ID": "20201218_HD_111111_20201218_HD_111111_1111_1000AB_NNNN_CCC_BE"
Your help is much appreciated with this query.
@jkauling - You can use the `rex` command.
You can add the below commands at the end of your query to see how many events contain given formatted events.
| rex "_1000AB_(?<extracted_number>\d+)_\w+_"
| search extracted_number=*
| stats count
- If you remove `| stats count` to see the extracted_number field as well.
- If the `ID` field is already being extracted you can replace regex with the below line to improve regex performance.
| rex field=ID "_1000AB_(?<extracted_number>\d+)_\w+_"
- If you also expect to see multiple places having this string (single event containing multiple of this unique string) and you like to count them separately, change the rex line with the below line:
| rex "_1000AB_(?<extracted_number>\d+)_\w+_" max_match=0 | mvexpand extracted_number
With grep, filter out just the numbers:
grep -Eo '[0-9]+-' file | sort -u | wc -l
@jkauling - You can use the `rex` command.
You can add the below commands at the end of your query to see how many events contain given formatted events.
| rex "_1000AB_(?<extracted_number>\d+)_\w+_"
| search extracted_number=*
| stats count
- If you remove `| stats count` to see the extracted_number field as well.
- If the `ID` field is already being extracted you can replace regex with the below line to improve regex performance.
| rex field=ID "_1000AB_(?<extracted_number>\d+)_\w+_"
- If you also expect to see multiple places having this string (single event containing multiple of this unique string) and you like to count them separately, change the rex line with the below line:
| rex "_1000AB_(?<extracted_number>\d+)_\w+_" max_match=0 | mvexpand extracted_number
Thanks this was helpfull/
Kindly accept the answer, so it will be useful for other visitors.