diff options
author | Denys Vlasenko | 2015-09-19 22:06:40 +0200 |
---|---|---|
committer | Denys Vlasenko | 2015-09-19 22:06:40 +0200 |
commit | 8aa7cf305ba5133721aa9852b398cbf1867fc857 (patch) | |
tree | 996b5b68c9b4004ffd65d954f19f5bbbe21bc71b /coreutils | |
parent | f085344d5c4de46d0ef3e15a97ef444fd7cc3194 (diff) | |
download | busybox-8aa7cf305ba5133721aa9852b398cbf1867fc857.zip busybox-8aa7cf305ba5133721aa9852b398cbf1867fc857.tar.gz |
sort: fix -kN,M handling (was including last separator into the comparison)
Testcase:
$ printf '%s\n' a/a:a a:b | sort -t: -k1,1
a:b
a/a:a
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/sort.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 1cb4c3e..36f0254 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -25,14 +25,14 @@ //usage: "\n -f Ignore case" //usage: "\n -g General numerical sort" //usage: "\n -i Ignore unprintable characters" -//usage: "\n -k Sort key" //usage: "\n -M Sort month" //usage: ) +//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G) //usage: "\n -n Sort numbers" //usage: IF_FEATURE_SORT_BIG( //usage: "\n -o Output to file" -//usage: "\n -k Sort by key" -//usage: "\n -t CHAR Key separator" +//usage: "\n -t CHAR Field separator" +//usage: "\n -k N[,M] Sort by Nth field" //usage: ) //usage: "\n -r Reverse sort order" //usage: IF_FEATURE_SORT_BIG( @@ -143,6 +143,9 @@ static char *get_key(char *str, struct sort_key *key, int flags) } } } + /* Remove last delim: "abc:def:" => "abc:def" */ + if (key_separator && j && end != 0) + end--; } if (!j) start = end; } @@ -163,7 +166,8 @@ static char *get_key(char *str, struct sort_key *key, int flags) if (start > len) start = len; } /* Make the copy */ - if (end < start) end = start; + if (end < start) + end = start; str = xstrndup(str+start, end-start); /* Handle -d */ if (flags & FLAG_d) { |