[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
The -o 0 field essentially selects the union of the join fields. For example,
given file phone:
!Name Phone Number
Don +1 123-456-7890
Hal +1 234-567-8901
Yasushi +2 345-678-9012
and file fax:
!Name Fax Number
Don +1 123-456-7899
Keith +1 456-789-0122
Yasushi +2 345-678-9011
(where the large expanses of white space are meant to each represent a
single <tab>), the command:
join -t "<tab>" -a 1 -a 2 -e '(unknown)' -o 0,1.2,2.2 phone fax
would produce:
!Name Phone Number Fax Number
Don +1 123-456-7890 +1 123-456-7899
Hal +1 234-567-8901 (unknown)
Keith (unknown) +1 456-789-0122
Yasushi +2 345-678-9012 +2 345-678-9011
>Fix:
Index: join.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/join/join.1,v
retrieving revision 1.7
diff -u -r1.7 join.1
--- join.1 2001/08/15 09:09:41 1.7
+++ join.1 2002/03/19 02:31:38
@@ -106,13 +106,16 @@
each line with matching join fields.
Each element of
.Ar list
-has the form
+has the either the form
.Ql file_number.field ,
where
.Ar file_number
is a file number and
.Ar field
-is a field number.
+is a field number, or the form
+.Ql 0
+.Pq zero ,
+representing the join field.
The elements of list must be either comma
.Pf ( Dq , Ns )
or whitespace separated.
@@ -216,9 +219,11 @@
.Sh STANDARDS
The
.Nm
-command is expected to be
-.St -p1003.2
-compatible.
+command conforms to
+.St -p1003.1-2001
+except for the requirement that there be no space between the
+.Fl a
+option and its argument.
.Sh SEE ALSO
.Xr awk 1 ,
.Xr comm 1 ,
Index: join.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/join/join.c,v
retrieving revision 1.10
diff -u -r1.10 join.c
--- join.c 1999/08/28 01:02:19 1.10
+++ join.c 2002/03/19 02:31:41
@@ -405,6 +405,8 @@
for (cnt = 0; cnt < olistcnt; ++cnt) {
if (olist[cnt].filenum == F->number)
outfield(lp, olist[cnt].fieldno, 0);
+ else if (olist[cnt].filenum == 0)
+ outfield(lp, F->joinf, 0);
else
outfield(lp, 0, 1);
}
@@ -427,7 +429,12 @@
/* Output a pair of lines according to the join list (if any). */
if (olist)
for (cnt = 0; cnt < olistcnt; ++cnt)
- if (olist[cnt].filenum == 1)
+ if (olist[cnt].filenum == 0) {
+ if (lp1->fieldcnt >= F1->joinf)
+ outfield(lp1, F1->joinf, 0);
+ else
+ outfield(lp2, F2->joinf, 0);
+ } else if (olist[cnt].filenum == 1)
outfield(lp1, olist[cnt].fieldno, 0);
else /* if (olist[cnt].filenum == 2) */
outfield(lp2, olist[cnt].fieldno, 0);
@@ -480,27 +487,33 @@
fieldarg(option)
char *option;
{
- u_long fieldno;
+ u_long fieldno, filenum;
char *end, *token;
while ((token = strsep(&option, ", \t")) != NULL) {
if (*token == '\0')
continue;
- if (token[0] != '1' && token[0] != '2' || token[1] != '.')
- errx(1, "malformed -o option field");
- fieldno = strtol(token + 2, &end, 10);
- if (*end)
+ if (token[0] == '0')
+ filenum = fieldno = 0;
+ else if ((token[0] == '1' || token[0] == '2') &&
+ token[1] == '.') {
+ filenum = token[0] - '0';
+ fieldno = strtol(token + 2, &end, 10);
+ if (*end)
+ errx(1, "malformed -o option field");
+ if (fieldno == 0)
+ errx(1, "field numbers are 1 based");
+ --fieldno;
+ } else
errx(1, "malformed -o option field");
- if (fieldno == 0)
- errx(1, "field numbers are 1 based");
if (olistcnt == olistalloc) {
olistalloc += 50;
if ((olist = realloc(olist,
olistalloc * sizeof(OLIST))) == NULL)
err(1, NULL);
}
- olist[olistcnt].filenum = token[0] - '0';
- olist[olistcnt].fieldno = fieldno - 1;
+ olist[olistcnt].filenum = filenum;
+ olist[olistcnt].fieldno = fieldno;
++olistcnt;
}
}
@@ -567,6 +580,8 @@
if (ap[2] != '\0')
break;
for (p = argv + 2; *p; ++p) {
+ if (p[0][0] == '0')
+ break;
if (p[0][0] != '1' &&
p[0][0] != '2' || p[0][1] != '.')
break;
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@xxxxxxxxxxx
with "unsubscribe freebsd-standards" in the body of the message