1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 03:12:48 +02:00

join: add -o 'auto' to output a constant number of fields per line

Lines with a different number of fields than the first line,
will be truncated or padded.

* src/join.c (prfields): A new function refactored from prjoin(),
to output all but the join field.
(prjoin): Don't swap line1 and line2 when line1 is blank
so that the padding is applied to the right place.
(main): Handle the -o 'auto' option.
* tests/misc/join: Add 6 new cases to test the auto format.
* NEWS: Mention the change in behavior.
Suggestion from Assaf Gordon
This commit is contained in:
Pádraig Brady
2011-01-05 11:52:54 +00:00
parent 68a734d66b
commit d4db0cb182
4 changed files with 96 additions and 37 deletions

View File

@@ -5701,8 +5701,8 @@ Do not check that both input files are in sorted order. This is the default.
@item -e @var{string}
@opindex -e
Replace those output fields that are missing in the input with
@var{string}.
Replace those output fields that are missing in the input with @var{string}.
I.E. missing fields specified with the @option{-12jo} options.
@item --header
@opindex --header
@@ -5733,10 +5733,17 @@ Join on field @var{field} (a positive integer) of file 2.
Equivalent to @option{-1 @var{field} -2 @var{field}}.
@item -o @var{field-list}
Construct each output line according to the format in @var{field-list}.
Each element in @var{field-list} is either the single character @samp{0} or
has the form @var{m.n} where the file number, @var{m}, is @samp{1} or
@samp{2} and @var{n} is a positive field number.
@itemx -o auto
If the keyword @samp{auto} is specified, infer the output format from
the first line in each file. This is the same as the default output format
but also ensures the same number of fields are output for each line.
Missing fields are replaced with the @option{-e} option and extra fields
are discarded.
Otherwise, construct each output line according to the format in
@var{field-list}. Each element in @var{field-list} is either the single
character @samp{0} or has the form @var{m.n} where the file number, @var{m},
is @samp{1} or @samp{2} and @var{n} is a positive field number.
A field specification of @samp{0} denotes the join field.
In most cases, the functionality of the @samp{0} field spec