🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix
Article #304

Re: Need help on a Unix utility to format text.

#304
From: Robert Felps
Date: Sat, 03 Nov 1990 02:51
61 lines
2504 bytes
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
Technical Details
Message-ID: <2249@megadon.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!tandem!zorch!vsi1!altos!megadon!clp
References: <2221@megadon.UUCP> <2242@megadon.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!tandem!zorch!vsi1!altos!megadon!clp
From: felps@convex.com (Robert Felps)
Newsgroups: comp.unix
Subject: Re: Need help on a Unix utility to format text.
Message-ID: <2249@megadon.UUCP>
Date: 3 Nov 90 02:51:29 GMT
References: <2221@megadon.UUCP> <2242@megadon.UUCP>
Sender: clp@megadon.UUCP
Lines: 61
Approved: clp@megadon.UUCP