* doc/coreutils.texi (split invocation): Document the new option.
* src/split.c (usage): Likewise.
(main): Process the new option much like --numeric-suffixes,
but with an adjusted alphabet.
* tests/split/numeric.sh: Refactor to support --hex mode.
* NEWS: Mention the new feature.
ignoring some non checksum lines. This also affects sha*sum and b2sum.
[bug introduced in coreutils-8.14]
+** New features
+
+ split supports a new --hex-suffixes[=from] option to create files with
+ lower case hexadecimal suffixes, similar to the --numeric-suffixes option.
+
* Noteworthy changes in release 8.27 (2017-03-08) [stable]
the number of files is less than @var{from}, a single run is assumed and the
minimum suffix length required is automatically determined.
+@item -x
+@itemx --hex-suffixes[=@var{from}]
+@opindex -x
+@opindex --hex-suffixes
+Like @option{--numeric-suffixes}, but use hexadecimal numbers (in lower case).
+
@item --additional-suffix=@var{suffix}
@opindex --additional-suffix
Append an additional @var{suffix} to output file names. @var{suffix}
{"additional-suffix", required_argument, NULL,
ADDITIONAL_SUFFIX_OPTION},
{"numeric-suffixes", optional_argument, NULL, 'd'},
+ {"hex-suffixes", optional_argument, NULL, 'x'},
{"filter", required_argument, NULL, FILTER_OPTION},
{"verbose", no_argument, NULL, VERBOSE_OPTION},
{"separator", required_argument, NULL, 't'},
-d use numeric suffixes starting at 0, not alphabetic\n\
--numeric-suffixes[=FROM] same as -d, but allow setting the start value\
\n\
+ -x use hex suffixes starting at 0, not alphabetic\n\
+ --hex-suffixes[=FROM] same as -x, but allow setting the start value\n\
-e, --elide-empty-files do not generate empty output files with '-n'\n\
--filter=COMMAND write to shell COMMAND; file name is $FILE\n\
-l, --lines=NUMBER put NUMBER lines/records per output file\n\
int this_optind = optind ? optind : 1;
char *slash;
- c = getopt_long (argc, argv, "0123456789C:a:b:del:n:t:u",
+ c = getopt_long (argc, argv, "0123456789C:a:b:del:n:t:ux",
longopts, NULL);
if (c == -1)
break;
break;
case 'd':
- suffix_alphabet = "0123456789";
+ case 'x':
+ if (c == 'd')
+ suffix_alphabet = "0123456789";
+ else
+ suffix_alphabet = "0123456789abcdef";
if (optarg)
{
if (strlen (optarg) != strspn (optarg, suffix_alphabet))
{
error (0, 0,
- _("%s: invalid start value for numerical suffix"),
+ (c == 'd') ?
+ _("%s: invalid start value for numerical suffix") :
+ _("%s: invalid start value for hexadecimal suffix"),
quote (optarg));
usage (EXIT_FAILURE);
}
#!/bin/sh
-# Show that split --numeric-suffixes[=from] works.
+# Test --{hex,numeric}-suffixes[=from]
# Copyright (C) 2012-2017 Free Software Foundation, Inc.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ split
-# Check default start from 0
printf '1\n2\n3\n4\n5\n' > in || framework_failure_
-split --numeric-suffixes --lines=2 in || fail=1
-cat <<\EOF > exp-1
-1
-2
-EOF
-cat <<\EOF > exp-2
-3
-4
-EOF
-cat <<\EOF > exp-3
-5
-EOF
-compare exp-1 x00 || fail=1
-compare exp-2 x01 || fail=1
-compare exp-3 x02 || fail=1
-# Check --numeric-suffixes=X
-split --numeric-suffixes=1 --lines=2 in || fail=1
-cat <<\EOF > exp-1
-1
-2
-EOF
-cat <<\EOF > exp-2
-3
-4
-EOF
-cat <<\EOF > exp-3
-5
-EOF
-compare exp-1 x01 || fail=1
-compare exp-2 x02 || fail=1
-compare exp-3 x03 || fail=1
+printf '%s\n' 1 2 > exp-0 || framework_failure_
+printf '%s\n' 3 4 > exp-1 || framework_failure_
+printf '%s\n' 5 > exp-2 || framework_failure_
-# Check that split failed when suffix length is not large enough for
-# the numerical suffix start value
-returns_ 1 split -a 3 --numeric-suffixes=1000 in 2>/dev/null || fail=1
+for mode in 'numeric' 'hex'; do
-# check invalid --numeric-suffixes start values are flagged
-returns_ 1 split --numeric-suffixes=-1 in 2> /dev/null || fail=1
-returns_ 1 split --numeric-suffixes=one in 2> /dev/null || fail=1
+ for start in 0 9; do
+ mode_option="--$mode-suffixes"
+ # check with and without specified start value
+ test $start != '0' && mode_option="$mode_option=$start"
+ split $mode_option --lines=2 in || fail=1
+
+ test $mode = 'hex' && format=x || format=d
+ for i in $(seq $start $(($start+2))); do
+ compare exp-$(($i-$start)) x$(printf %02$format $i) || fail=1
+ done
+ done
+
+ # Check that split failed when suffix length is not large enough for
+ # the numerical suffix start value
+ returns_ 1 split -a 3 --$mode-suffixes=1000 in 2>/dev/null || fail=1
+
+ # check invalid --$mode-suffixes start values are flagged
+ returns_ 1 split --$mode-suffixes=-1 in 2> /dev/null || fail=1
+ returns_ 1 split --$mode-suffixes=one in 2> /dev/null || fail=1
+done
Exit $fail