Hi @maba
Thanks for the links and data. For what its worth (and at risk of being flamed for being WAY OT for this forum), here is a Logstash config which seems to produce what you need:
input {
file {
path => "/Users/me/Documents/Code/logstash/input.txt"
ignore_older => 0
codec => multiline {
pattern => "^\d{1,2}\;\d{2}\/\d{2}.*"
negate => "true"
what => "previous"
}
}
}
filter {
if [message] =~ /.*Date\s\:\;\d{1,2}\/\d{1,2}\/\d{4}.*/ {
grok {
match => { "message" => ".*Date\s\:\;(?<date>\d{1,2}\/\d{1,2}\/\d{4}).*\:\;(?<i>\d*).*numero\s(?<z>\d*)" }
add_field => { "myComment" => "#Comment" }
}
}
if [myComment] {
mutate {
add_field => { "output" => "%{myComment}: %{date};%{i};%{z}"}
remove_field => ["myComment", "tags", "path", "host", "date", "i", "z", "@version", "message", "@timestamp" ]
}
}
if [message] =~ /RILEVAZIONE\sCOSTI/ {
mutate {
rename => { "message" => "i" }
split => { "i" => ";" }
add_field => { "split" => "1" }
}
if [split] == "1" {
mutate {
gsub => ["[i]", "\r\n", "" ]
gsub => ["[i]", "\s*", "" ]
remove_field => [ "tags", "@version", "@timestamp", "split", "path", "host" ]
}
mutate {
add_field => { "a1" => "%{[i][0]};%{[i][1]};%{[i][2]};%{[i][3]} - %{[i][4]};%{[i][5]};%{[i][6]};%{[i][7]};%{[i][8]};%{[i][9]};"}
add_field => { "a2" => "%{[i][10]};;;%{[i][14]};;%{[i][17]};Abbuoini attivi;%{[i][20]}€;%{[i][21]};%{[i][26]};%{[i][27]};"}
add_field => { "a3" => "%{[i][28]};%{[i][29]};%{[i][30]};%{[i][31]};%{[i][32]};%{[i][33]};%{[i][37]};150.00;" }
add_field => { "result" => "%{a1}%{a2}%{a3}" }
remove_field => [ "a1","a2","a3","i" ]
}
}
}
}
output {
stdout {
codec => rubydebug
}
}
That will produce (based on your test data):
{
"output" => "#Comment: 23/06/2017;1;9999999"
}
{
"result" => "1;02/01/2017;02/01/2017;10 - RILEVAZIONECOSTI;Effettivo;No;A;/;1;//;;;Incremento;;47/5/29;Abbuoini attivi;-200,00€;abcd;1;CR100-centrodicostodipro;1;FF-dispesaFUEL;1;BD-BUDIESEL;1;15-intercompanyversoIT;-200,00;150.00;"
}
{
"result" => "2;02/01/2017;02/01/2017;10 - RILEVAZIONECOSTI;Effettivo;No;A;/;1;//;;;Incremento;;39/5/18;Abbuoini attivi;1.000,00€;dcba;1;CR100-centrodicostodipro;1;FF-tipologiadispesaFUEL;1;BD-BUDIESEL;1;15-intercompanyversoIT;1.000,00;150.00;"
}
{
"result" => "33;02/01/2017;02/01/2017;10 - RILEVAZIONECOSTI;Effettivo;No;A;/;1;//;;;Incremento;;39/5/18;Abbuoini attivi;150,00€;nuovacommessa;1;CR100-centrodicostodipro;1;FF-tipologiadispesaFUEL;1;BD-BUDIESEL;1;15-intercompanyversoIT;150,00;150.00;"
}
{
"result" => "34;03/01/2017;03/01/2017;10 - RILEVAZIONECOSTI;Effettivo;No;A;/;1;//;;;Incremento;;39/5/36;Abbuoini attivi;300,00€;nuovacommessa;1;CR100-centrodicostodipro;1;FF-tipologiadispesaFUEL;1;BD-BUDIESEL;1;15-intercompanyversoIT;300,00;150.00;"
}
You can, when you are happy, very easily change the output block to send to a file. More info here:
https://www.elastic.co/guide/en/logstash/2.3/plugins-outputs-file.html