Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ucla-cs!sdcrdcf!burdvax!wrp From: wrp@burdvax.PRC.Unisys.COM (William R. Pringle) Newsgroups: comp.unix.questions Subject: Re: awk or sed question Message-ID: <3892@burdvax.PRC.Unisys.COM> Date: Fri, 3-Jul-87 10:16:45 EDT Article-I.D.: burdvax.3892 Posted: Fri Jul 3 10:16:45 1987 Date-Received: Sat, 4-Jul-87 17:23:46 EDT References: <4780@columbia.UUCP> Sender: news@burdvax.PRC.Unisys.COM Distribution: world Organization: Unisys/Paoli Research Center, Paoli, PA Lines: 61 in article <4780@columbia.UUCP>, agw@broadway.columbia.edu (Art Werschulz) says: > > > Hi all. > > I have a file consisting of some lines that have 80 chars or fewer, > and some with more than 80 characters (in fact, some may have more > than 160 characters). I wish to break up only the >80-char lines, so > that no line has more than 80 chars. > > Here's the catch: I want to break the long lines only at whitespace. > Thus, I can't use > > % fold -80 foo.tex > > since a space in the middle of a word would be disatrous. > > Any suggestions? > > Art Werschulz > > ARPAnet: agw@columbia.edu > USEnet: ... seismo!columbia!agw > BITnet: agw%columbia.edu@wiscvm > CCNET: agw@columbia > ATTnet: Columbia University (212) 280-3610 280-2736 > Fordham University (212) 841-5323 841-5396 ===================== Here is a little script that I use to do that. Hope it helps. ---------------- Cut Here --------- #!/bin/sh # # fold lines at whitespace # # by Bill Pringle # burdvax!wrp # sed -e 's/ / /g' $* | # convert tabs to 8 spaces awk - ' BEGIN { N = 80 } { if ((n = length($0)) <= N) print else { LEN = N for (i = 1; n > N; n -= LEN) { while (substr($0,LEN+i-1,1) != " ") { LEN -= 1 } if (i==1) { printf "%s\\\n", substr($0, i, LEN) } else { printf "> %s\\\n", substr($0, i, LEN) } i += LEN; } printf "> %s\\\n", substr($0,i) } } '