When a file name of "-" is given, read from standard input (SUSv3)

This commit is contained in:
tjr 2002-05-24 09:56:18 +00:00
parent 1ccb024996
commit 2292a0fbef
2 changed files with 17 additions and 8 deletions

View File

@ -61,8 +61,13 @@ utility selects portions of each line (as specified by
.Ar list )
from each
.Ar file
(or the standard input by default), and writes them to the
standard output.
and writes them to the standard output.
If no
.Ar file
arguments are specified, or a file argument is a single dash
.Pq Ql \&- ,
.Nm
reads from from the standard input.
The items specified by
.Ar list
can be in terms of column position or in terms of fields delimited

View File

@ -119,13 +119,17 @@ main(argc, argv)
rval = 0;
if (*argv)
for (; *argv; ++argv) {
if (!(fp = fopen(*argv, "r"))) {
warn("%s", *argv);
rval = 1;
continue;
if (strcmp(*argv, "-") == 0)
fcn(stdin, "stdin");
else {
if (!(fp = fopen(*argv, "r"))) {
warn("%s", *argv);
rval = 1;
continue;
}
fcn(fp, *argv);
(void)fclose(fp);
}
fcn(fp, *argv);
(void)fclose(fp);
}
else
fcn(stdin, "stdin");