App-CSVUtils
view release on metacpan or search on metacpan
script/csv-find-values view on Meta::CPAN
our $VERSION = '1.036'; # VERSION
my $cmdline = Perinci::CmdLine::Any->new(
url => "/App/CSVUtils/csv_find_values/csv_find_values",
program_name => "csv-find-values",
log => 1,
read_config => 0,
read_env => 0,
use_utf8 => 1,
);
$cmdline->run;
# ABSTRACT: Find specified values in a CSV field
# PODNAME: csv-find-values
__END__
=pod
=encoding UTF-8
=head1 NAME
csv-find-values - Find specified values in a CSV field
=head1 VERSION
This document describes version 1.036 of csv-find-values (from Perl distribution App-CSVUtils), released on 2025-02-04.
=head1 SYNOPSIS
B<csv-find-values> B<L<--help|/"--help, -h, -?">> (or B<L<-h|/"--help, -h, -?">>, B<L<-?|/"--help, -h, -?">>)
B<csv-find-values> B<L<--version|/"--version, -v">> (or B<L<-v|/"--version, -v">>)
B<csv-find-values> [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<--eval|/"--eval=s">>=I<any>|B<L<--eval-json|/"--eval=s">>=I<json>|B<L<-e|/"-...
=head1 DESCRIPTION
Example input:
# product.csv
sku,name,is_active,description
SKU1,foo,1,blah
SK2,bar,1,blah
SK3B,baz,0,blah
SKU2,qux,1,blah
SKU3,quux,1,blah
SKU14,corge,0,blah
Check whether specified values are found in the C<sku> field, print message when
they are (search case-insensitively):
% csv-find-values product.csv sku sku1 sk3b sku15 -i
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
Print message when values are I<not> found instead:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=not_found
'sku15' is NOT found in field 'sku'
Always print message:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=always
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
'sku15' is NOT found in field 'sku'
Do custom action with Perl code, code will receive C<$_> (the value being
evaluated), C<$found> (bool, whether it is found in the field), C<$rownum> (the
row number the value is found in), C<$data_rownum> (the data row number the value
is found in, equals C<$rownum> - 1):
% csv-find-values product.csv sku1 sk3b sku15 -i -e 'if ($found) { print "$_ found\n" } else { print "$_ NOT found\n" }'
sku1 found
sk3b found
sku15 NOT found
There is an option to do fuzzy matching, where similar values will be suggested
when exact match is not found.
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--eval-json>=I<s>, B<-e>
Perl code (JSON-encoded).
See C<--eval>.
=item B<--eval>=I<s>
Perl code.
=item B<--field>=I<s>*, B<-f>
Field name.
Can also be specified as the 2nd command-line argument.
=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.
script/csv-find-values view on Meta::CPAN
=head2 Output options
=over
=item B<--format>=I<s>
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is
chosen depending on the application and/or whether output destination is
interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.
=item B<--json>
Set output format to json.
=item B<--naked-res>
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
C<--naked-res> so you just get:
[1,2,3]
=item B<--page-result>
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program
is not specified, a suitable default e.g. C<less> is chosen.
=item B<--print-when>=I<s>
Default value:
"found"
Valid values:
["found","not_found","always"]
Overriden by the C<--eval> option.
=item B<--view-result>
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer
program to view the temporary file. If a viewer program is not chosen, a
suitable default, e.g. the browser, is chosen.
=back
=head2 Searching options
=over
=item B<--fuzzy>
(No description)
=item B<--ignore-case>, B<-i>, B<--ci>
(No description)
=back
=head2 Other options
=over
=item B<--help>, B<-h>, B<-?>
Display help message and exit.
=item B<--version>, B<-v>
Display program's version and exit.
=back
=head1 COMPLETION
This script has shell tab completion capability with support for several
shells.
=head2 bash
To activate bash completion for this script, put:
complete -C csv-find-values csv-find-values
in your bash startup (e.g. F<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.
( run in 0.885 second using v1.01-cache-2.11-cpan-39bf76dae61 )