Tayto
Tayto

Reputation: 59

Issue with the sort command in open stack server list in an ubuntu environment

I am trying to sort the output here as per compute systems:

enter image description here

I tried with openstack server list --all --long -c ID -c Name -c Status -c Host | sort -k4 but it doesn't work.

Can someone help me how to can I sort this as per Host name? where 460001 number is in ascending order under Host column.

PS: the below is sample and is not an actual output from any anywhere.

Regards, Tayto

Upvotes: 1

Views: 527

Answers (1)

Victor Lee
Victor Lee

Reputation: 2678

Just append --sort-column Host to your openstack command. But you should make sure that the Host column can't have None or null value.

Check from openstack server list -h:

output formatters:
  output formatter options

  -f {csv,json,table,value,yaml}, --format {csv,json,table,value,yaml}
                        the output format, defaults to table
  -c COLUMN, --column COLUMN
                        specify the column(s) to include, can be repeated to
                        show multiple columns
  --sort-column SORT_COLUMN
                        specify the column(s) to sort the data (columns
                        specified first have a priority, non-existing columns
                        are ignored), can be repeated

Or if you don't have --sort-column option, you should sort -k8 but not -k4.

Or use openstack server list --all --long -c ID -c Name -c Status -c Host -f value | sort -k4 just with -f value, but it will separate the columns by blank space.

Upvotes: 1

Related Questions