GNU bug report logs -
#19240
cut 8.22 adds newline
Previous Next
Reported by: John Kendall <john <at> capps.com>
Date: Mon, 1 Dec 2014 16:44:01 UTC
Severity: normal
Tags: notabug
Done: Eric Blake <eblake <at> redhat.com>
Bug is archived. No further changes may be made.
Full log
Message #45 received at 19240 <at> debbugs.gnu.org (full text, mbox):
Paul Eggert wrote:
> On 12/04/2014 10:41 AM, John Kendall wrote:
>> echo "$FILE ===========================\c"| cut -c1-30
>
> Since you're going to have to rewrite it anyway if you want it to be portable, I suggest doing it this way:
>
> printf '%.30s' "$FILE ==========================="
>
> as it's a lot more efficient anyway.
Yes, that's what I've done. The corner case I mentioned is
handled badly by this, however. In the corner case $FILE
is a list of files separated by a newlines. Solaris cut would
list them and then the ============= would be tacked
on to the last line:
filename1
filename2
filename3
filename4
filename5 ========================= matches
When printf is used, it truncates the list of filenames if the sum
of them exceeds 30 chars in length. The format string %.30s
doesn't treat embedded newlines specially:
filename1
filename2
filename3 ========================= matches
filenames start getting lopped off.
I'll rework the code. It worked for 15 years, don't be too
offended by it. :)
This bug report was last modified 10 years and 171 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.