Splunk Search

How to sort my table columns?

vnithin123
Engager

Can someone help in sorting table columns. Table contains
Row1,Row2,Row3,Row11,Row22,Row33
I tried sorting in order. but it shows below

Row1
Row11
Row2
Row22
Row3
Row33

Result should be -
Row1
Row2
Row3
Row11
Row22
Row33

Thanks

Tags (3)
0 Karma
1 Solution

gvmorley
Contributor

Hi,

One way you could sort this, would be to extract the number from the field containing "Row" and then sort by that number.

For example, assuming your "Row" field is called "row_no":

| rex field="row_no" "Row(?<row_sort>\d+)"
| sort + row_sort

If you didn't want the "sort" field afterwards, you could then remove it with:

| fields - row_sort

To see a full example, try this:

| makeresults
| fields - _time
| eval row_no=mvrange(1,34) | mvexpand row_no | eval row_no="Row".row_no
| rex field="row_no" "Row(?<row_sort>\d+)"
| sort + row_sort

Hopefully that will get you the result that you're looking for.

View solution in original post

gvmorley
Contributor

Hi,

One way you could sort this, would be to extract the number from the field containing "Row" and then sort by that number.

For example, assuming your "Row" field is called "row_no":

| rex field="row_no" "Row(?<row_sort>\d+)"
| sort + row_sort

If you didn't want the "sort" field afterwards, you could then remove it with:

| fields - row_sort

To see a full example, try this:

| makeresults
| fields - _time
| eval row_no=mvrange(1,34) | mvexpand row_no | eval row_no="Row".row_no
| rex field="row_no" "Row(?<row_sort>\d+)"
| sort + row_sort

Hopefully that will get you the result that you're looking for.

jlvix1
Communicator

What is your query?

0 Karma
Get Updates on the Splunk Community!

Why You Can't Miss .conf25: Unleashing the Power of Agentic AI with Splunk & Cisco

The Defining Technology Movement of Our Lifetime The advent of agentic AI is arguably the defining technology ...

Deep Dive into Federated Analytics: Unlocking the Full Power of Your Security Data

In today’s complex digital landscape, security teams face increasing pressure to protect sprawling data across ...

Your summer travels continue with new course releases

Summer in the Northern hemisphere is in full swing, and is often a time to travel and explore. If your summer ...