0

how can i get the output below in sort sequence order of 1,2,3,10,12 instead of 1,10,12,2,3 ?

avi@tech> get  hardwareNumber=    productNumber

hardwareNumber=1                               productNumber 526845
hardwareNumber=10                              productNumber 526845
hardwareNumber=12                              productNumber 526845
hardwareNumber=2                               productNumber 526845
hardwareNumber=3                               productNumber 526845
1
  • Could you provide details on the shell and operating system you are using so that we can better assist? Thanks. Commented Jan 29, 2021 at 3:29

2 Answers 2

1

Pipe the output to

sort -t= -nk2,2
  • -t indicates the separator
  • -n sorts numerically, i.e. what you want
  • -k2,2 tells sort to use the second column (and only the second column) to sort the lines.
0

You need sort with the -n flag, from man sort:

-n, --numeric-sort
           compare according to string numerical value
$ sort -nt'=' -k2 file
hardwareNumber=1                               productNumber 526845
hardwareNumber=2                               productNumber 526845
hardwareNumber=3                               productNumber 526845
hardwareNumber=10                              productNumber 526845
hardwareNumber=12                              productNumber 526845

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.