How to get sort command working with data separated by | (pipe character) ?Consider this sample file called x which have two fields:axis-AXIS|OKaxis-AXISR|OKaxis-AXISD2X|OKaxis-AXISA|OKaxis-AXISD1|OKaxis-AXIS1RX|OKaxis-AXISR1M|OKaxis-AXISD2|FALSEaxis-AXISMD|FALSEaxis-AXISM|FALSEaxis-AXISE|OKaxis-AXISD|OKMy locale: echo $LC_ALLCWhen it is sorted the character | seems to be part of the key producing a strange assortment:sort -t| xaxis-AXIS1RX|OKaxis-AXISA|OKaxis-AXISD1|OKaxis-AXISD2X|OKaxis-AXISD2|FALSEaxis-AXISD|OKaxis-AXISE|OKaxis-AXISMD|FALSEaxis-AXISM|FALSEaxis-AXISR1M|OKaxis-AXISR|OKaxis-AXIS|OKSpecifying a field key sort -t| -k1 x nothing changes.
Wrong order with sort command
sort;locale
Without the closing field number with -k, it will consider all fields starting from 1. You need :sort -k1,1 -t'|' file.txtTest :$ sort -k1,1 -t'|' file.txt axis-AXIS|OKaxis-AXIS1RX|OKaxis-AXISA|OKaxis-AXISD|OKaxis-AXISD1|OKaxis-AXISD2|FALSEaxis-AXISD2X|OKaxis-AXISE|OKaxis-AXISM|FALSEaxis-AXISMD|FALSEaxis-AXISR|OKaxis-AXISR1M|OKIf your locale is not C, you can set it on the fly :LC_ALL=C sort -k1,1 -t'|' file.txt