Skip to content

Instantly share code, notes, and snippets.

@imweijh
Created December 17, 2021 09:59
Show Gist options
  • Save imweijh/5b7af16da8e475081cc958d28234c4fe to your computer and use it in GitHub Desktop.
Save imweijh/5b7af16da8e475081cc958d28234c4fe to your computer and use it in GitHub Desktop.
logstash gsub regex replace use capture group
input {
generator {
lines => [
"whatever|1|BA|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|BP|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|SA|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|SP|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|BC|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|SC|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||61033|",
"whatever|1|BF|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||",
"whatever|1|SF|110100|11:19:39|1|101.00000|whatever|123456789||10.000|||"
]
count => 1
}
}
filter {
mutate {
gsub => [
"message", "^(\w+\|1)\|SA", "\1|S",
"message", "^(\w+\|1)\|SP", "\1|S",
"message", "^(\w+\|1)\|BA", "\1|B",
"message", "^(\w+\|1)\|BP", "\1|B",
"message", "^(\w+\|1)\|BC", "\1|C",
"message", "^(\w+\|1)\|SC", "\1|C",
"message", "^(\w+\|1)\|BF", "\1|F",
"message", "^(\w+\|1)\|SF", "\1|F"
]
}
}
output { stdout { codec => rubydebug } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment