Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aix-pm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
aix-pm
Commits
efe85d37
Commit
efe85d37
authored
1 year ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
allow --col option to use * as a wildcard for all remaining column names
parent
a072dcd5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/csv.pl
+47
-3
47 additions, 3 deletions
modules/util/csv.pl
with
47 additions
and
3 deletions
modules/util/csv.pl
+
47
−
3
View file @
efe85d37
...
...
@@ -88,7 +88,7 @@ my $op_mode= 'cat';
my
$show_header
=
0
;
my
$UTF8
=
0
;
my
$out_file
;
my
@columns
;
my
@
show_
columns
;
my
@sort_columns
;
my
@set_columns
;
my
$sort_numeric
=
0
;
...
...
@@ -137,7 +137,7 @@ while (defined (my $arg= shift (@ARGV)))
elsif
(
$opt
eq
'
dumper
')
{
$view
=
'
dumper
';
}
elsif
(
$opt
eq
'
Dumper
')
{
$view
=
'
Dumper
';
}
elsif
(
$opt
eq
'
setcol
')
{
push
(
@set_columns
,
split
('
,
',
$val
||
shift
(
@ARGV
)));
}
elsif
(
$opt
eq
'
col
')
{
push
(
@columns
,
split
('
,
',
$val
||
shift
(
@ARGV
)));
}
elsif
(
$opt
eq
'
col
')
{
push
(
@
show_
columns
,
split
('
,
',
$val
||
shift
(
@ARGV
)));
}
elsif
(
$opt
eq
'
sort
')
{
push
(
@sort_columns
,
split
('
,
',
$val
||
shift
(
@ARGV
)));
}
elsif
(
$opt
eq
'
num
')
{
$sort_numeric
=
1
;
}
elsif
(
$opt
eq
'
nsort
')
{
push
(
@sort_columns
,
split
('
,
',
$val
||
shift
(
@ARGV
)));
$sort_numeric
=
1
;
}
...
...
@@ -353,6 +353,8 @@ while (my $fnm= shift (@PARS))
$csv
->
merge_csv_file
(
$fnm
);
}
my
@columns
;
if
(
defined
(
$json_file_to_load
))
{
my
$data
=
Util::JSON::
read_json_file
(
$json_file_to_load
);
...
...
@@ -377,7 +379,49 @@ if (defined ($json_file_to_load))
}
# print "cols=", Dumper ($csv->{'columns'}), "\n";
@columns
=
@
{
$csv
->
{
columns
}}
if
(
!
@columns
&&
exists
(
$csv
->
{
columns
})
&&
defined
(
$csv
->
{
columns
}));
# ---------------------------------------------------------------------
# Set up the list of columns which are then used or saved
# If a list of columns is defined via --col <name>[,<name>]*, then this
# is used, otherwise the list of columns is taken from the CSV file
# itself.
# <name> should come from the list of available columns, but it does
# not have to, e.g. when a CSV file should receive an empty new column
# for later filling in.
# If <name> is '*', then all unused available columns are added to
# the end.
# The same column name can be added multiple times in the --col option;
# we assume, the users knows what they do.
# ---------------------------------------------------------------------
if
(
!
@columns
)
{
my
@available_columns
=
@
{
$csv
->
{
columns
}}
if
(
exists
(
$csv
->
{
columns
})
&&
defined
(
$csv
->
{
columns
}));
if
(
@show_columns
)
{
my
%inserted
;
my
$show_rest_too
=
0
;
foreach
my
$c
(
@show_columns
)
{
if
(
$c
eq
'
*
')
{
$show_rest_too
=
1
;
next
;
}
push
(
@columns
,
$c
);
$inserted
{
$c
}
=
1
;
}
if
(
$show_rest_too
)
{
foreach
my
$c
(
@available_columns
)
{
push
(
@columns
,
$c
)
unless
(
$inserted
{
$c
});
}
}
}
else
{
@columns
=
@available_columns
;
}
}
print
__LINE__
,
"
columns:
",
join
('
',
@columns
),
"
\n
";
if
(
@sort_columns
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment