uniq -c formatting
Rob Landley
rob at landley.net
Sun Jul 23 13:35:29 PDT 2006
On Tuesday 18 July 2006 7:41 am, Eric Spakman wrote:
> Hi Robert,
> >
> >> Hi list,
> >>
> >>
> >> Somewhere between busybox-1.0 and 1.2 the formatting of uniq -c
> >> changed. Previously some leading spaces where present but with 1.2 this
> >> is no longer the case. The new behaviour brakes some formatting in the
> >> output of scripts (for example the shorewall program,
> >> www.shorewall.net).
> >>
> >> Simple test case.
> >> file "test" contents: test1 test2
> >>
> >> busybox-1.0 #cat test | uniq -c
> >> 1 test1
> >> 1 test2
> >>
> >>
> >> busybox-1.2 #cat test | uniq -c
> >> 1 test1
> >> 1 test2
> >>
> >>
> >> I'm not sure what the desired susv3 behaviour should be, but a
> >> "full" version of uniq has the busybox-1.0 behaviour.
> >>
> >
> > i'm not sure that that aesthetic change should be blamed for any scripts
> > breaking. the man page for uniq reads:
> >
> > "A field is a run of whitespace, then non-whitespace characters."
> >
> >
> > leading whitespace should generally be regarded as entirely optional. if a
> > script breaks because that leading whitespace isn't there anymore, i would
> > suggest that it's the *script* that's broken.
> >
> It's not that the script is breaking, but the formatting of its output.
> Anyway, it was more a question of why the output of uniq changed, if it
> was intentional or simply overlooked.
It was intentional, not just because the tab is pointless but because because
GNU is violating the letter of susv3:
http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html
OUTPUT FILES
If the -c option is specified, the output file shall be empty or each line
shall be of the form:
"%d %s", <number of duplicates>, <line>
otherwise, the output file shall be empty or each line shall be of the form:
"%s", <line>
There's no \t inside the quotes before the %d, so we shouldn't have one (at
least not without a good reason, which there isn't).
svn 11469 comments as to why the change was made (svn log coreutils/uniq.c
comes in handy here, or try the web browsy thingy), and there's a message on
this from me in the archives (9/14/2005, "Making a test suite for uniq").
Rob
--
Never bet against the cheap plastic solution.
More information about the busybox
mailing list