App-CSVUtils
view release on metacpan or search on metacpan
script/csv-sort-fields-by-spec view on Meta::CPAN
url => "/App/CSVUtils/csv_sort_fields_by_spec/csv_sort_fields_by_spec",
program_name => "csv-sort-fields-by-spec",
log => 1,
read_config => 0,
read_env => 0,
use_utf8 => 1,
);
$cmdline->run;
# ABSTRACT: Sort CSV fields by spec
# PODNAME: csv-sort-fields-by-spec
__END__
=pod
=encoding UTF-8
=head1 NAME
csv-sort-fields-by-spec - Sort CSV fields by spec
=head1 VERSION
This document describes version 1.036 of csv-sort-fields-by-spec (from Perl distribution App-CSVUtils), released on 2025-02-04.
=head1 SYNOPSIS
B<csv-sort-fields-by-spec> B<L<--help|/"--help, -h, -?">> (or B<L<-h|/"--help, -h, -?">>, B<L<-?|/"--help, -h, -?">>)
B<csv-sort-fields-by-spec> B<L<--version|/"--version, -v">> (or B<L<-v|/"--version, -v">>)
B<csv-sort-fields-by-spec> [B<L<--ci|/"--ci, -i">>|B<L<-i|/"--ci, -i">>] [B<L<--debug|/"--debug">>|B<L<--log-level|/"--log-level=s">>=I<level>|B<L<--quiet|/"--quiet">>|B<L<--trace|/"--trace">>|B<L<--verbose|/"--verbose">>] [B<L<--format|/"--format=s"...
=head1 DESCRIPTION
This is a thin wrapper for L<csv-sort-fields> to allow you to sort "by
spec". Sorting by spec is an advanced form of sorting by example. In addition to
specifying strings of examples, you can also specify regexes or Perl sorter
codes. For more details, see the sorting backend module L<Sort::BySpec>.
To specify a regex on the command-line, use one of these forms:
/.../
qr(...)
and to specify Perl code on the command-line, use this form:
sub { ... }
For example, modifying from example in C<Sort::BySpec>'s Synopsis, you want to
sort these fields:
field1..field15 field42
as follow: 1) put fields with odd numbers first in ascending order; 2) put the
specific fields field4, field2, field42 in that order; 3) put the remaining
fields of even numbers in descending order. To do this:
% perl -E'say join(",",map {"field$_"} 1..15,42)' | csv-sort-fields-by-spec - \
'qr([13579]\z)' 'sub { my($a,$b)=@_; for($a,$b){s/field//} $a<=>$b }' \
field4 field2 field42 \
'sub { my($a,$b)=@_; for($a,$b){s/field//} $b<=>$a }'
The result:
field1,field3,field5,field7,field9,field11,field13,field15,field4,field2,field42,field14,field12,field10,field8,field6
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--ci>, B<-i>
(No description)
=item B<--input-skip-num-lines>=I<s>
Number of lines to skip before header row.
This can be useful if you have a CSV files (usually some generated reports,
sometimes converted from spreadsheet) that have additional header lines or info
before the CSV header row.
See also the alternative option: C<--input-skip-until-pattern>.
=item B<--input-skip-until-pattern>=I<s>
Skip rows until the first header row matches a regex pattern.
This is an alternative to the C<--input-skip-num-lines> and can be useful if you
have a CSV files (usually some generated reports, sometimes converted from
spreadsheet) that have additional header lines or info before the CSV header
row.
With C<--input-skip-num-lines>, you skip a fixed number of lines. With this
option, rows will be skipped until the first field matches the specified regex
pattern.
=item B<--reverse>, B<-r>
(No description)
=item B<--sortsub-args-json>=I<s>
Arguments to pass to Sort::Sub routine (JSON-encoded).
See C<--sortsub-args>.
=item B<--sortsub-args>=I<s>%
Arguments to pass to Sort::Sub routine.
( run in 0.481 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )