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
========================================================================================================
MO                                                      Attribute         Value
========================================================================================================
hardwareNumber=1                               productNumber 526845
hardwareNumber=10                              productNumber 526845
hardwareNumber=12                              productNumber 526845
hardwareNumber=2                               productNumber 526845
hardwareNumber=3                               productNumber 526845
========================================================================================================
marc_hll
  • 11
  • 2
  • Since you have header and footer, I would write a small script which splits the whole output into header part, body part and footer part, then sort the body part according your criterion, and put everything back together for outputting. – user1934428 Jan 28 '21 at 08:17

1 Answers1

2

If you remove the header and footer (you can add them back after sorting)

sort -t= -k2 -n file-with-no-header-or-footer.txt

which uses = as the delimiter, key 2 and -n for numeric, produces

hardwareNumber=1                               productNumber 526845
hardwareNumber=2                               productNumber 526845
HardwareNumber=3                               productNumber 526845
hardwareNumber=10                              productNumber 526845
hardwareNumber=12                              productNumber 526845
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I tried this but it didnt work, is it wrong with my string? get hardwareNumber= productNumber | sort -t= -k2 -n | – marc_hll Jan 28 '21 at 16:46
  • well, "didn't work" does not help to understand your problem. Show input, output, etc. – Diego Torres Milano Jan 28 '21 at 19:24
  • still same output as before, I don't have a txt file hardwareNumber=1 productNumber 526845 hardwareNumber=10 productNumber 526845 hardwareNumber=12 productNumber 526845 hardwareNumber=2 productNumber 526845 hardwareNumber=3 productNumber 526845 – marc_hll Jan 29 '21 at 19:05