Hi everyone,
I have the following search:
index=xyz
| eval new_field = field
| eval length=len(new_fied)
| eval new_field = substr(new_field, 1, len(new_field) -15)
| table new_field,field,length
With that I'm removing the last 15 digits of "new_field"
So this query works but the problem is that my "new_field" have 4 different lenghts and for each one I need to do something different then I'd like to create a condition to extract last 15 numbers only if the lenght is 27 (one of the lenghts)
sample:
011332255667799114466990033 turns out > 011332255667
I was trying to do something like below:
| eval new_field = if((len(new_field)==27, "0", new_field)substr(new_field, 1, len(new_field) -15))
For sure this is not working, but just to show my idea and what I need to accomplish. When the "new_field" has <> 27 digits it goes wrong
Any idea?
Thanks
Hi @WesleyFranklin,
you eval command has two problems:
with the first eval you take you number without the last 15 digits and not the last 15 digits, then the second eval is wrong.
So if you wabt to extract last 15 numbers only if the lenght is 27, you should try something like this:
| eval new_field=if(len(new_field)=27,substr(new_field,len(new_field)-15,15),new_field)
Ciao.
Giuseppe
Depending on how much you want to remove for each of your 4 lengths, you could do something like this
| eval length=len(new_field)
| eval new_field = case(length=27,substr(new_field, 1, length -15),length=30,substr(new_field,1,length-20),1==1,new_field)
Hi @ITWhisperer
Thank you for your reply.
It worked.
Is it possible also remove the fisrt 5 numbers THEN remove the last 15 using case?
Hi @WesleyFranklin,
you eval command has two problems:
with the first eval you take you number without the last 15 digits and not the last 15 digits, then the second eval is wrong.
So if you wabt to extract last 15 numbers only if the lenght is 27, you should try something like this:
| eval new_field=if(len(new_field)=27,substr(new_field,len(new_field)-15,15),new_field)
Ciao.
Giuseppe
Hi @gcusello
Thank you for your reply.
It worked.
Is it possible also remove the fisrt 5 numbers THEN remove the last 15 using this if condition?
Hi @WesleyFranklin,
yes, it's possible.
Only to understand: do you want to remove the first 5 digits of the field when lenght is greather then 27 and after remove always the last 15 digitis, or do you want to take the last 10 digits ?
In the second case the solution is the same of the previous answer, in the second case you have to use twise the eval command:
| eval new_field=if(len(new_field)>=27,substr(new-field),6, 100)
| eval new_field=if(len(new_field)>=22,substr(new_field,len(new_field)-15,15),new_field)
I use the first eval to delete the first 5 digits and the second eval to tak the following 15 digits
Anyway, see the approach and modify the eval commands to adapt them to your need:
Ciao.
Giuseppe
P.S.: Karma Points are appreciated by all the Contributors 😉
Hey @gcusello
Oh I see, now I'll adjust as far as I need it.
That's awesome.
Thank you so much.
Hi @WesleyFranklin,
good for you, see next time!
please accept one answer for the other people of Community.
Ciao and happy splunking
Giuseppe
P.S.: Karma Points are appreciated by all the Contributors 😉