7 td2mrkv - Transform tabular data into multi-record key-value (MRKV) format.
13 =item -s, --separator I<STR>
15 String to separate field name from content.
16 Default is TAB (C<\t>).
20 Note, sorting by keys does not support duplicated column names.
22 =item -V, --sort-values
28 getent passwd | tr : "\t" | td-add-headers USER PW UID GID GECOS HOME SHELL | td-select +ALL -PW | td2mrkv
32 mrkv2td(1), td2html(1)
39 $OptCaseInsensitiveSort = 0;
41 's|separator=s' => \
$OptSeparator,
42 'K|sort-keys!' => \
$OptSortKeys,
43 'V|sort-values!' => \
$OptSortValues,
44 'I|case-insensitive-sort!' => \
$OptCaseInsensitiveSort,
47 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
48 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
52 return $OptCaseInsensitiveSort ?
lc($_[0]) : $_[0];
55 process_header
(scalar <STDIN
>);
57 @OrderedHeaders = do { my $pos = 0; map {{name
=>$_, orig_idx
=>$pos++}} @Header };
61 @OrderedHeaders = sort { sortkey
($a->{name
}) cmp sortkey
($b->{name
}) } @OrderedHeaders;
66 my @Field = read_record
(\
*STDIN
);
68 my @columns = @OrderedHeaders;
72 @columns = sort { sortkey
($Field[$a->{orig_idx
}]) cmp sortkey
($Field[$b->{orig_idx
}]) } @OrderedHeaders;
75 for my $col (@columns)
77 printf "%s%s%s%s", $col->{name
}, $OptSeparator, $Field[$col->{orig_idx
}], $RS;