I have a text file for acronyms. Each line starts with the acronym (in uppercase), usually up to 4 letters, and then "=" and then the explanation. For example,
...
EST=Eastern Standard Time
OVS=Open vSwitch
IPMI=Intelligent Platform Management Interface
...
IHV=Independent Hardware Vendor
ISV=Independent Software Vendor
...
I want to sort this text file, in bash, by ascending order according to the acronym, which is the first string (till "=") in each line. Any suggestions as to the best way to achieve this ?
Take a look at the
sort
command (man sort
). It has all manner of options for delimiting keys and establishing sorting parameters.In your simple case:
would set the primary key to be everything up to the
=
and sort them in ascending order.There is a "short form" for this, also (thanks @karafka!):
Check out
man sort
for details on sort order, using multiple keys and other options.