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.038 of csv-sort-fields-by-spec (from Perl distribution App-CSVUtils), released on 2026-07-09.

=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<--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.

Each value is a name-value pair, use I<key=value> syntax. Can be specified multiple times.

=item B<--specs-json>=I<s>

Spec entries (JSON-encoded).

See C<--specs>.

Can also be specified as the 2nd command-line argument and onwards.

=item B<--specs>=I<s>*

Spec entries.

Can also be specified as the 2nd command-line argument and onwards.

=back

=head2 Input options

=over

=item B<--input-escape-char>=I<s>



( run in 0.857 second using v1.01-cache-2.11-cpan-9169edd2b0e )