简体   繁体   中英

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:

在此处输入图像描述

I tried with openstack server list --all --long -c ID -c Name -c Status -c Host | sort -k4 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

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM