Splunk Search

How to sort and match column based on last 4 strings based on column1 (ref1)?

pemancha
Explorer

This is my first post here! _I am new and I am learning

Hi Experts,

I have data like below coming into a csv file.

ref1 toref1
16YcK36 bc46
20Sdj60 fg64
13Nbc46 dj60
15Nfg64 nf32
13Tnf32 cK36
   


and my end result, I would like the table to be like below: (Edited: My search should be sorted (column no 2) - should match the last 4 with column 1). Please refer to below table. Thanks in Advance.

ref1_tobe toref1_tobe
16YcK36 cK36
20Sdj60 dj60
13Nbc46 bc46
15Nfg64 fg64
13Tnf32 nf32
Labels (5)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not sure what you are asking for - is it just the last 4 characters of the ref field?

| eval toref=substr(ref1_tobe,-4,4)
0 Karma

pemancha
Explorer

Thank for you reply but It needs to be re-arrange and sort based on the left column, like table below:

IF 16YcK36 this is in the first row, then cK36 must on that row as well, because the data at 2nd column it goes in random and not sorted according to the last 3 string of column 1. 

ref1_tobetoref1_tobe
16YcK36cK36
20Sdj60dj60
13Nbc46bc46
15Nfg64fg64
13Tnf32nf32
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Your toref1_tobe column is not sorted - is this just a typo or is there some logic behind this sort order?

If you want to sort by a field use something like this

| sort 0 toref1_tobe
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...