jay@hqda-ai.ARPA (Jay Hiser) (06/27/88)
I'm responsible for 3 CCI 6/32s that run SysV (CCI's rel. 2.22). I'm looking for replacements for some of the utils that I'm used to with BSD. head: the opposite of 'tail'. Shouldn't be hard to implement this in c, but I don't want to reinvent the wheel. Thought this was part of 'std' unix, but its not in my sys's docs. yes: pipe the output to some other program that expects 'y' or 'n'. I've got a file full of 'y\n' that essentially duplicates yes's function, but it doesn't seem as neat as yes. nroff: I realize that this has been unbundled (dwb?) from SysV. I still need to format man pages. Our OA sys can handle virtually all my formatting needs, except for nroff -man. Maybe this could be a GNU application some day? Anybody have an alternate source for this useful stuff? Thanks,
gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/27/88)
In article <6007@hqda-ai.ARPA> jay@hqda-ai.ARPA (Jay Hiser) writes: >head: the opposite of 'tail'. if [ $# -eq 0 ] then n=10 else case $1 in [0-9]*) n=$1; shift;; *) n=10;; esac fi exec sed -e ${n}q $*
lkb@theceg.UUCP (Lawrence Keith Blische) (06/28/88)
From article <8171@brl-smoke.ARPA>, by gwyn@brl-smoke.ARPA (Doug Gwyn ): > In article <6007@hqda-ai.ARPA> jay@hqda-ai.ARPA (Jay Hiser) writes: >>head: the opposite of 'tail'. > > if [ $# -eq 0 ] > then n=10 > else case $1 in > [0-9]*) n=$1; shift;; > *) n=10;; > esac > fi > exec sed -e ${n}q $* I don't want to start the "whose's head is best" :-) war but the following version seems to better adhere to the BSD SYNOPSIS given in my Berkeley (4.3) doc for head(1): head [-count] [file ...] It also overcomes a descrepency between my SysV sed(1) man page (which indicates that sed takes multiple input files) and reality (which says it dosen't :-( ). : Bourne Shell Script if [ $# -eq 0 ] then sed 10q else case $1 in -[0-9]*) n="`echo $1|cut -c2-`" shift;; *) n="10";; esac for file in $* do sed ${n}q $file done fi ---------------------------------------------------------------------- Larry Blische ...!cp1!sarin\ The Computer Engineering Group, Inc. !wb3ffv!theceg!lkb +1 301 282 5876 (9-5 ET) ...!aplcen/
leo@philmds.UUCP (Leo de Wit) (06/29/88)
In article <8171@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes: >In article <6007@hqda-ai.ARPA> jay@hqda-ai.ARPA (Jay Hiser) writes: >>head: the opposite of 'tail'. > >if [ $# -eq 0 ] >then n=10 >else case $1 in > [0-9]*) n=$1; shift;; > *) n=10;; > esac >fi >exec sed -e ${n}q $* I like that. He (Jay) also writes: >yes: pipe the output to some other program that expects 'y' or 'n'. #!/bin/sh # yes - be repetitively affirmative case $# in 0) set y;; esac exec sed ' : again p b again' <<EOT $1 EOT Now there is still nroff to take care of. Anybody feels an urge to add his "one"-liner, using sed 8-) ? Leo.
bostic@OKEEFFE.BERKELEY.EDU (Keith Bostic) (07/01/88)
The BSD version of head(1), while not PD, is freely redistributable. And has just recently been cleaned up. Enjoy. Forget about sed. --keith # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # head.c # echo x - head.c sed 's/^X//' >head.c << 'END-of-head.c' X/* X * Copyright (c) 1980, 1987 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, 1987 Regents of the University of California.\n\ X All rights reserved.\n"; X#endif /* not lint */ X X#ifndef lint Xstatic char sccsid[] = "@(#)head.c 5.4 (Berkeley) 6/29/88"; X#endif /* not lint */ X X#include <stdio.h> X#include <ctype.h> X/* X * head - give the first few lines of a stream or of each of a set of files X * X * Bill Joy UCB August 24, 1977 X */ X Xmain(argc, argv) X int argc; X char **argv; X{ X register int ch, cnt; X int firsttime, linecnt = 10; X X if (argc > 1 && argv[1][0] == '-') { X if (!isdigit(argv[1][1])) { X fprintf(stderr, "head: illegal option -- %c\n", argv[1][1]); X goto usage; X } X if ((linecnt = atoi(argv[1] + 1)) < 0) { Xusage: fputs("usage: head [-line_count] [file ...]\n", stderr); X exit(1); X } X --argc; ++argv; X } X /* setlinebuf(stdout); */ X for (firsttime = 1, --argc, ++argv;; firsttime = 0) { X if (!*argv) { X if (!firsttime) X exit(0); X } X else { X if (!freopen(*argv, "r", stdin)) { X fprintf(stderr, "head: can't read %s.\n", *argv); X exit(1); X } X if (argc > 1) { X if (!firsttime) X putchar('\n'); X printf("==> %s <==\n", *argv); X } X ++argv; X } X for (cnt = linecnt; cnt; --cnt) X while ((ch = getchar()) != EOF) X if (putchar(ch) == '\n') X break; X } X /*NOTREACHED*/ X} END-of-head.c exit