line length
Jonathan I. Kamens
jik at athena.mit.edu
Wed May 10 22:47:11 AEST 1989
In article <127 at tdl.UUCP> raulin at tdl.UUCP (Raulin Olivera) writes:
>In article <160 at ohsu-hcx.UUCP>, mkb at ohsu-hcx.UUCP (Marilyn Bushway) writes:
>> If I have output of 132 characters and I want it to be 80 characters
>> is there a unix command to change the line length???
>I would probalbly handle it with and AWK script depending on the size
>of the file. The AWK script could be run within your shell script.
>An example might be:
> [ example of doing it using awk ]
>If you need speed I would do it in C. An example might be
> [ example of doing it using C ]
Can you say, "Reinvent the wheel?"
The shar file below says it all, I think. I wouldn't normally post
source code for a Berkeley program in comp.unix.questions when it can
be gotten from ftp and uucp archive sites, but it's so short, what the
hell :-)
Isn't Berkeley Unix a wonderful thing?
Jonathan Kamens USnail:
MIT Project Athena 410 Memorial Drive, No. 223F
jik at Athena.MIT.EDU Cambridge, MA 02139-4318
Office: 617-253-4261 Home: 617-225-8218
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: fold.1 fold.c
# Wrapped by jik at pit-manager on Wed May 10 08:46:00 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fold.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fold.1'\"
else
echo shar: Extracting \"'fold.1'\" \(823 characters\)
sed "s/^X//" >'fold.1' <<'END_OF_FILE'
X.\" Copyright (c) 1980 Regents of the University of California.
X.\" All rights reserved. The Berkeley software License Agreement
X.\" specifies the terms and conditions for redistribution.
X.\"
X.\" @(#)fold.1 6.1 (Berkeley) 4/29/85
X.\"
X.TH FOLD 1 "April 29, 1985"
X.UC
X.SH NAME
Xfold \- fold long lines for finite width output device
X.SH SYNOPSIS
X.B fold
X[
X\-width
X] [
Xfile ...
X]
X.SH DESCRIPTION
X.I Fold
Xis a filter which will fold the contents of the specified files,
Xor the standard input if no files are specified,
Xbreaking the lines to have maximum width
X.I width.
XThe default for
X.I width
Xis 80.
X.I Width
Xshould be a multiple of 8 if tabs are present, or the tabs should
Xbe expanded using
X.IR expand (1)
Xbefore coming to
X.I fold.
X.SH SEE\ ALSO
Xexpand(1)
X.SH BUGS
XIf underlining is present it may be messed up by folding.
END_OF_FILE
if test 823 -ne `wc -c <'fold.1'`; then
echo shar: \"'fold.1'\" unpacked with wrong size!
fi
# end of 'fold.1'
fi
if test -f 'fold.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fold.c'\"
else
echo shar: Extracting \"'fold.c'\" \(2311 characters\)
sed "s/^X//" >'fold.c' <<'END_OF_FILE'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley. The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1980 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)fold.c 5.2 (Berkeley) 6/29/88";
X#endif /* not lint */
X
X#include <stdio.h>
X/*
X * fold - fold long lines for finite output devices
X *
X * Bill Joy UCB June 28, 1977
X */
X
Xint fold = 80;
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X register c;
X FILE *f;
X
X argc--, argv++;
X if (argc > 0 && argv[0][0] == '-') {
X fold = 0;
X argv[0]++;
X while (*argv[0] >= '0' && *argv[0] <= '9')
X fold *= 10, fold += *argv[0]++ - '0';
X if (*argv[0]) {
X printf("Bad number for fold\n");
X exit(1);
X }
X argc--, argv++;
X }
X do {
X if (argc > 0) {
X if (freopen(argv[0], "r", stdin) == NULL) {
X perror(argv[0]);
X exit(1);
X }
X argc--, argv++;
X }
X for (;;) {
X c = getc(stdin);
X if (c == -1)
X break;
X putch(c);
X }
X } while (argc > 0);
X exit(0);
X}
X
Xint col;
X
Xputch(c)
X register c;
X{
X register ncol;
X
X switch (c) {
X case '\n':
X ncol = 0;
X break;
X case '\t':
X ncol = (col + 8) &~ 7;
X break;
X case '\b':
X ncol = col ? col - 1 : 0;
X break;
X case '\r':
X ncol = 0;
X break;
X default:
X ncol = col + 1;
X }
X if (ncol > fold)
X putchar('\n'), col = 0;
X putchar(c);
X switch (c) {
X case '\n':
X col = 0;
X break;
X case '\t':
X col += 8;
X col &= ~7;
X break;
X case '\b':
X if (col)
X col--;
X break;
X case '\r':
X col = 0;
X break;
X default:
X col++;
X break;
X }
X}
END_OF_FILE
if test 2311 -ne `wc -c <'fold.c'`; then
echo shar: \"'fold.c'\" unpacked with wrong size!
fi
# end of 'fold.c'
fi
echo shar: End of shell archive.
exit 0
More information about the Comp.unix.questions
mailing list