GNU bug report logs -
#12482
Feature Request: support for int, octal, and hex types in seq --format
Previous Next
To reply to this bug, email your comments to 12482 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#12482
; Package
coreutils
.
(Fri, 21 Sep 2012 01:06:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Craig Sanders <cas <at> taz.net.au>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Fri, 21 Sep 2012 01:06:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Package: Coreutils
Severity: wishlist
seq only supports floating point types like f and g in the --format string.
Other types, including i,d,o,u,x,X would also be useful.
e.g. "seq --format 'prefix%02isuffix' 1 50" to print zero-padded 1-50 with
user-specified prefix and suffix strings.
see
http://unix.stackexchange.com/questions/48750/creating-numerous-directories-using-mkdir/48758#48758
for a real-world usage example.
Thanks,
craig
--
craig sanders <cas <at> taz.net.au>
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#12482
; Package
coreutils
.
(Fri, 21 Sep 2012 07:28:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 12482 <at> debbugs.gnu.org (full text, mbox):
Craig Sanders wrote:
> seq only supports floating point types like f and g in the --format string.
>
> Other types, including i,d,o,u,x,X would also be useful.
>
> e.g. "seq --format 'prefix%02isuffix' 1 50" to print zero-padded 1-50 with
> user-specified prefix and suffix strings.
IMO custom format strings for pre- or suffixing are not seq's job.
The OP wanted a little shell solution to create 50 directories
with a fixed prefix and suffix, so what about this?
seq -w 50 | sed 's/^/prefix/; s/$/suffix/' | xargs mkdir
Have a ncie day,
Berny
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#12482
; Package
coreutils
.
(Fri, 21 Sep 2012 08:21:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 12482 <at> debbugs.gnu.org (full text, mbox):
retitle 12482 RFE: seq: add support for int, octal, hex formats in --format
thanks
Voelker, Bernhard wrote:
> Craig Sanders wrote:
>
>> seq only supports floating point types like f and g in the --format string.
>>
>> Other types, including i,d,o,u,x,X would also be useful.
>>
>> e.g. "seq --format 'prefix%02isuffix' 1 50" to print zero-padded 1-50 with
>> user-specified prefix and suffix strings.
>
> IMO custom format strings for pre- or suffixing are not seq's job.
I agreed, initially. The texinfo documentation gives examples
of how to convert seq output to hexadecimal (%x) using printf:
--------------------
If you want hexadecimal integer output, you can use `printf' to
perform the conversion:
$ printf '%x\n' `seq 1048575 1024 1050623`
fffff
1003ff
1007ff
For very long lists of numbers, use xargs to avoid system
limitations on the length of an argument list:
$ seq 1000000 | xargs printf '%x\n' | tail -n 3
f423e
f423f
f4240
To generate octal output, use the printf `%o' format instead of `%x'.
--------------------
> The OP wanted a little shell solution to create 50 directories
> with a fixed prefix and suffix, so what about this?
>
> seq -w 50 | sed 's/^/prefix/; s/$/suffix/' | xargs mkdir
Hmm...
The first time I ran an example like the above, I used -w
without realizing that there was no need, since the printf
format would handle the fixed width part.
(the disadvantage with this approach is that you have to pre-compute
the width and use that number in the printf format, whereas in Bernie's
example, that's done automatically by seq -w. This suggests that seq's
--equal-width (-w) option *would* be handy in conjunction with the requested
integer format directives. Then, we'd get the benefit of -w along with
the more direct use of a seq format string. )
$ seq -w 12 | xargs printf 'a-%02x-b\n'
a-01-b
a-02-b
a-03-b
a-04-b
a-05-b
a-06-b
a-07-b
a-printf: 08: value not completely converted
00-b
a-printf: 09: value not completely converted
00-b
a-0a-b
a-0b-b
a-0c-b
[Exit 123]
That looks like a bug, but printf is actually required to reject
those two input strings. A leading "0" means octal.
This does what you want:
$ seq 12 | xargs printf 'a-%02x-b\n'
a-01-b
a-02-b
a-03-b
a-04-b
a-05-b
a-06-b
a-07-b
a-08-b
a-09-b
a-0a-b
a-0b-b
a-0c-b
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#12482
; Package
coreutils
.
(Fri, 21 Sep 2012 15:13:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 12482 <at> debbugs.gnu.org (full text, mbox):
On Fri, Sep 21, 2012 at 10:19:13AM +0200, Jim Meyering wrote:
> Voelker, Bernhard wrote:
> > Craig Sanders wrote:
> >
> >> seq only supports floating point types like f and g in the --format
> >> string.
> >>
> >> Other types, including i,d,o,u,x,X would also be useful.
> >>
> >> e.g. "seq --format 'prefix%02isuffix' 1 50" to print zero-padded
> >> 1-50 with user-specified prefix and suffix strings.
> >
> > IMO custom format strings for pre- or suffixing are not seq's job.
the printf formats I suggested for seq are not specifically about
prefixing or suffixing, they were just part of an example..
what i requested was non-floating point formats (the suffix and prefix
strings are just a side-benefit of printf) - decimal, octal, and hex
integer printf formats d,o,x, etc. if it supports floating-point, why
not fixed or int?
in fact, why floating-point at all? i can think of hundreds of uses in
a shell script for printf-formatted ints from seq (and some for hex and
even a few for octal), but not a single one for floating point. i'd
use perl or python or something else if i wanted to do floating-point
calculations (perl has a nice Math::BigFloat module and python, of
course, has numpy and scipy).
> I agreed, initially. The texinfo documentation gives examples
> of how to convert seq output to hexadecimal (%x) using printf:
yes, i know there are numerous ways to post-process seq's output. I
even included a few in my answer to the stackexchange question i linked
to.
if there's some reason why floating point is possible but
the integer formats are not then fair enough....but it doesn't
make sense to me to arbitrarily declare that floating-point
printf support is OK but not integer.
the examples using printf and xargs and so on are both obvious and
missing the point. this bug report is not about them. it's about seq's
incomplete support for printf.
> (the disadvantage with this approach is that you have to pre-compute
> the width and use that number in the printf format, whereas in Bernie's
> example, that's done automatically by seq -w. This suggests that seq's
> --equal-width (-w) option *would* be handy in conjunction with the requested
> integer format directives. Then, we'd get the benefit of -w along with
> the more direct use of a seq format string. )
yes!
> That looks like a bug, but printf is actually required to reject
> those two input strings. A leading "0" means octal.
yeah, ran into that myself and thought WTF until i realised 'oh yeah. octal'.
> $ seq 12 | xargs printf 'a-%02x-b\n'
yep, but i already knew that.
i'm not asking for help to solve a problem. I'm submitting a wishlist
level bug report for a feature enhancement to support more of
printf's formatting capabilities in seq.
craig
--
craig sanders <cas <at> taz.net.au>
This bug report was last modified 12 years and 277 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.