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!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...