#!/usr/bin/perl
#
# dbcolsplittorows.pm
# Copyright (C) 1991-2018 by John Heidemann <johnh@isi.edu>
#
# This program is distributed under terms of the GNU general
# public license, version 2. See the file COPYING
# in $dblibdir for details.
#
=head1 NAME
dbcolsplittorows - split an existing column into multiple new rows
=head1 SYNOPSIS
dbcolsplittorows [-C ElementSeperator] [-e null] [-E] [-N enumerated-name] column [column...]
=head1 DESCRIPTION
Split column into pieces, outputting one row for each piece.
By default, any empty fields are ignored.
If an empty field value is given with -e, then they produce output.
When a null value is given, empty fields at the beginning and end of
lines are suppressed (like perl split). Unlike perl, if ALL fields
are empty, we generate one (and not zero) empty fields.
The inverse of this commend is L<dbfilepivot>.
=head1 OPTIONS
=over 4
=item B<-C S> or B<--element-separator S>
Specify the separator used to split columns.
(Defaults to a single underscore.)
=item B<-E> or B<--enumerate>
Enumerate output columns: rather than assuming the column name uses
the element separator, we keep it whole and fill in with indexes
starting from 0.
=item B<-N> or B<--new-name> N
Name the new column N for enumeration.
Defaults to C<index>.
=item B<-e E> or B<--empty E>
give value E as the value for empty (null) records
=back
=for comment
begin_standard_fsdb_options
This module also supports the standard fsdb options:
=over 4
=item B<-d>
Enable debugging output.
=item B<-i> or B<--input> InputSource
Read from InputSource, typically a file name, or C<-> for standard input,
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.
=item B<-o> or B<--output> OutputDestination
Write to OutputDestination, typically a file name, or C<-> for standard output,
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.
=item B<--autorun> or B<--noautorun>
By default, programs process automatically,
but Fsdb::Filter objects in Perl do not run until you invoke
the run() method.
The C<--(no)autorun> option controls that behavior within Perl.
=item B<--help>
Show help.
=item B<--man>
Show full manual.
=back
=for comment
end_standard_fsdb_options
=head1 SAMPLE USAGE
=head2 Input:
#fsdb name uid
John_Heidemann 2274
Greg_Johnson 2275
Root 0
# this is a simple database
# | dbcol fullname uid
# | dbcolrename fullname name
=head2 Command:
cat data.fsdb | dbcolsplittorows name
=head2 Output:
#fsdb name uid
John 2274
Heidemann 2274
Greg 2275
Johnson 2275
Root 0
# this is a simple database
# | dbcol fullname uid
# | dbcolrename fullname name
# | dbcolsplittorows name
=head1 SEE ALSO
L<Fsdb(1)>.
L<dbcolmerge(1)>.
L<dbcolsplittocols(1)>.
L<dbcolrename(1)>.
L<dbfilepvot(1)>.
=cut
# WARNING: This code is derived from dbcolsplittorows.pm; that is the master copy.
use Fsdb::Filter::dbcolsplittorows;
my $f = new Fsdb::Filter::dbcolsplittorows(@ARGV);
$f->setup_run_finish; # or could just --autorun
exit 0;
=head1 AUTHOR and COPYRIGHT
Copyright (C) 1991-2018 by John Heidemann <johnh@isi.edu>
This program is distributed under terms of the GNU general
public license, version 2. See the file COPYING
with the distribution for details.
=cut
1;