From 2ab948d5dc114db80d27f32184e231c5074a1f9f Mon Sep 17 00:00:00 2001 From: Gerhard Gonter <ggonter@gmail.com> Date: Fri, 1 Dec 2023 19:32:11 +0100 Subject: [PATCH] added --skip=<n> option --- modules/util/Util/Simple_CSV.pm | 9 +++++++++ modules/util/csv.pl | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/util/Util/Simple_CSV.pm b/modules/util/Util/Simple_CSV.pm index 5edd1d9..a26cc8c 100644 --- a/modules/util/Util/Simple_CSV.pm +++ b/modules/util/Util/Simple_CSV.pm @@ -166,6 +166,15 @@ sub load_csv_file return undef unless (defined ($fi_open)); + if (exists($obj->{skip})) + { + my $skip= $obj->{skip}; + if ($skip =~ /^\d+$/ && $skip > 0) + { + while ($skip-- > 0) { <FI>; } # skip a number of lines + } + } + $obj->load_csv_file_headings (*FI) unless ($obj->{'no_headings'}); if (@{$obj->{columns}} # NOTE: columns might have been defined using $obj->define_columns(...) diff --git a/modules/util/csv.pl b/modules/util/csv.pl index 666ea34..aa35bbd 100755 --- a/modules/util/csv.pl +++ b/modules/util/csv.pl @@ -98,6 +98,7 @@ my $view= 'matrix'; # values: matrix, extended, header, json, dumper my $all= 0; # for extend view, sofar... my $find_pattern= undef; # this is used for a pattern match my $search_string= undef; # this is used to select a certain value in a column +my $skip= undef; # used for option --in <fieldname> <field_value>+ my @search_strings; @@ -121,6 +122,7 @@ while (defined (my $arg= shift (@ARGV))) if ($opt eq 'merge') { $op_mode= 'merge'; $view= 'no'; } elsif ($opt eq 'dump') { $DUMP_FILE= $val || shift (@ARGV); } elsif ($opt eq 'out') { $out_file= $val || shift (@ARGV); } + elsif ($opt eq 'skip') { $skip= $val || shift (@ARGV); } elsif ($opt eq 'find') { $find_pattern= $val || shift (@ARGV); } # TODO: allow multiple patterns! elsif ($opt eq 'search' || $opt eq 'select') { # TODO: allow multiple searches! @@ -337,10 +339,8 @@ EOX $csv->set ('fidef' => \&fidef3); } -if (defined ($max_items)) -{ - $csv->set ( max_items => $max_items ); -} +$csv->set ( max_items => $max_items ) if (defined ($max_items)); +$csv->set ( skip => $skip ) if (defined ($skip)); my $fnm= shift (@PARS); $csv->load_csv_file ($fnm); -- GitLab