Index: src/usr.bin/head/head.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/head/head.1,v retrieving revision 1.4.2.6 diff -u -r1.4.2.6 head.1 --- src/usr.bin/head/head.1 15 Jul 2002 06:33:12 -0000 1.4.2.6 +++ src/usr.bin/head/head.1 25 Jul 2002 12:01:44 -0000 @@ -41,6 +41,7 @@ .Sh SYNOPSIS .Nm .Op Fl n Ar count | Fl c Ar bytes +.Op Fl s Ar skipcount .Op Ar .Sh DESCRIPTION This filter displays the first @@ -59,6 +60,14 @@ where .Dq XXX is the name of the file. +.Pp +If +.Ar skipcount +is specified, the +.Nm head +utility skips the specified number of lines or bytes before displaying +the requested +.Ar count . .Sh DIAGNOSTICS .Ex -std .Sh SEE ALSO Index: src/usr.bin/head/head.c =================================================================== RCS file: /home/ncvs/src/usr.bin/head/head.c,v retrieving revision 1.10.2.1 diff -u -r1.10.2.1 head.c --- src/usr.bin/head/head.c 16 Feb 2002 12:29:04 -0000 1.10.2.1 +++ src/usr.bin/head/head.c 18 Feb 2002 14:08:20 -0000 @@ -60,8 +60,8 @@ * Bill Joy UCB August 24, 1977 */ -void head __P((FILE *, int)); -void head_bytes __P((FILE *, int)); +void head __P((FILE *, int, int)); +void head_bytes __P((FILE *, int, int)); void obsolete __P((char *[])); void usage __P((void)); @@ -72,11 +72,11 @@ { register int ch; FILE *fp; - int first, linecnt = -1, bytecnt = -1, eval = 0; + int first, linecnt = -1, bytecnt = -1, skipcnt = 0, eval = 0; char *ep; obsolete(argv); - while ((ch = getopt(argc, argv, "n:c:")) != -1) + while ((ch = getopt(argc, argv, "n:c:s:")) != -1) switch(ch) { case 'c': bytecnt = strtol(optarg, &ep, 10); @@ -88,6 +88,11 @@ if (*ep || linecnt <= 0) errx(1, "illegal line count -- %s", optarg); break; + case 's': + skipcnt = strtol(optarg, &ep, 10); + if (*ep || skipcnt <= 0) + errx(1, "illegal skip count -- %s", optarg); + break; case '?': default: usage(); @@ -111,40 +116,52 @@ first ? "" : "\n", *argv); first = 0; } - if (bytecnt == -1) - head(fp, linecnt); - else - head_bytes(fp, bytecnt); + if (bytecnt == -1) { + if (skipcnt) head(fp, skipcnt, 0); + head(fp, linecnt, 1); + } else { + if (skipcnt) head_bytes(fp, skipcnt, 0); + head_bytes(fp, bytecnt, 1); + } (void)fclose(fp); } - } else if (bytecnt == -1) - head(stdin, linecnt); - else - head_bytes(stdin, bytecnt); + } else if (bytecnt == -1) { + if (skipcnt != 0) + head(stdin, skipcnt, 0); + head(stdin, linecnt, 1); + } else { + if (skipcnt != 0) + head_bytes(stdin, skipcnt, 0); + head_bytes(stdin, bytecnt, 1); + } exit(eval); } void -head(fp, cnt) +head(fp, cnt, out) FILE *fp; register int cnt; + int out; { char *cp; int error, readlen; while (cnt && (cp = fgetln(fp, &readlen)) != NULL) { - error = fwrite(cp, sizeof(char), readlen, stdout); - if (error != readlen) - err(1, "stdout"); + if (out) { + error = fwrite(cp, sizeof(char), readlen, stdout); + if (error != readlen) + err(1, "stdout"); + } cnt--; } } void -head_bytes(fp, cnt) +head_bytes(fp, cnt, out) FILE *fp; register int cnt; + int out; { char buf[4096]; register int readlen; @@ -157,8 +174,9 @@ readlen = fread(buf, sizeof(char), readlen, fp); if (readlen == 0) break; - if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) - err(1, "stdout"); + if (out) + if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) + err(1, "stdout"); cnt -= readlen; } }