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.   :)  







Reply via email to