[comp.unix] Need help on a Unix utility to format text.

maxc1222@ucselx.sdsu.edu (Generic Account 1222) (10/17/90)

I need some help!! I'm am looking for a Unix utility that will get
standard input and format it to 72 columns max. I looked at 'fmt'
and it was putting the word which fell on the 72nd column on the
following line.  I need something which will break any word
at the 72nd column regardless.

Thanks in advance,

LP

kole@convex.UUCP (John P. Kole) (10/21/90)

In article <2221@megadon.UUCP> maxc1222@ucselx.sdsu.edu (Generic Account 1222) writes:
>
>I need some help!! I'm am looking for a Unix utility that will get
>standard input and format it to 72 columns max. I looked at 'fmt'
>and it was putting the word which fell on the 72nd column on the
>following line.  I need something which will break any word
>at the 72nd column regardless.
>
>Thanks in advance,
>
>LP

Try colrm(1).

jpr@hombre.masa.com (Jean-Pierre Radley) (10/26/90)

In article <2221@megadon.UUCP> maxc1222@ucselx.sdsu.edu (Generic Account 1222) writes:
>I need some help!! I'm am looking for a Unix utility that will get
>standard input and format it to 72 columns max. I looked at 'fmt'
>and it was putting the word which fell on the 72nd column on the
>following line.  I need something which will break any word
>at the 72nd column regardless.

Cheap and dirty approach:

Try running nroff on your input. Without any macros defined at all, it seems to
default to right-justified 72 column text.

Two consecutive line-feeds in the input tell it to start a new paragraph.
It also will issue line-feeds to come to some multiple of 66 lines.
-- 

 Jean-Pierre Radley          HIGH-Q	     jpr@jpradley	CIS: 72160,1341

rer@hpfcdc.fc.hp.com (Rob Robason) (10/30/90)

lp> I need something which will break any word at the 72nd column
lp> regardless.

try fold(1).

perl@step.UUCP (Robert Perlberg) (11/03/90)

Also available on some systems: fold(1) which will not lose any data
like colrm will.

Robert Perlberg
Dean Witter Reynolds Inc., New York
{murphy | philabs | chuo}!step!perl
	-- "I am not a language ... I am a free man!"

felps@convex.com (Robert Felps) (11/03/90)

In <2242@megadon.UUCP> rer@hpfcdc.fc.hp.com (Rob Robason) writes:
>lp> I need something which will break any word at the 72nd column
>lp> regardless.

>try fold(1).

And if your not on a BSD system or derivative which has fold try the
following awk prog:
-----------------------------------------------------------
#
#########################################################
#
#  This script folds long lines into 60-character lines.
#  A "\e" is appended to indicate that the line was
#  folded, and the residue is then processed.  It is
#  assumed that the input file does not contain tabs.
#  The input line is only broken on spaces.
#
#  To run this script:
#     awk -f fold.script filename
#
#########################################################
#
BEGIN   {
        N = 57  # fold at column 57
}

{       if ((n = length($0)) <= N)
                print                   # fold is unnecessary
        else    {
                split($0,word);
                line = "";
                cnt = 0;
                for (i = 1; length(line) < N; i++)      {
                        line = line " " word[i];
                        cnt = cnt + 1;
                }
                line = line " ";
                if (cnt == NF)
                        printf "%s\n", line
                else    {
                        printf "%s\e\n", line;
                        line = "";
                        for (i = cnt+1; i <= NF; i++)   {
                                line = line " " word[i];
                                cnt = cnt + 1;
                        }
                        printf "%s\n", line
                }
        }
}
-----------------------------------------------------------

You may want to modify it to be more flexible but it does the basic
work already.

enjoy,
Robert Felps                                felps@convex.com
Convex Computer Corp                        OS System Specialist
3000 Waterview Parkway                      Tech. Assistant Ctr
Richardson, Tx.  75083                      1(800) 952-0379