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
33a14f9d
Commit
33a14f9d
authored
7 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
added simple TSV converter
parent
dd90d8b9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/util/Util/tsv.pm
+13
-0
13 additions, 0 deletions
modules/util/Util/tsv.pm
modules/util/json2tsv.pl
+99
-0
99 additions, 0 deletions
modules/util/json2tsv.pl
with
112 additions
and
0 deletions
modules/util/Util/tsv.pm
+
13
−
0
View file @
33a14f9d
...
...
@@ -7,13 +7,26 @@ sub new
my
$class
=
shift
;
my
$label
=
shift
;
my
$columns
=
shift
;
my
@par
=
shift
;
my
$obj
=
{
label
=>
$label
,
cols
=>
$columns
,
rows
=>
[]
};
bless
$obj
,
$class
;
$obj
->
set
(
@par
);
$obj
;
}
sub
set
{
my
$self
=
shift
;
my
%par
=
@_
;
foreach
my
$par
(
keys
%par
)
{
$self
->
{
$par
}
=
$par
{
$par
};
}
}
sub
add_items
{
my
$self
=
shift
;
...
...
This diff is collapsed.
Click to expand it.
modules/util/json2tsv.pl
0 → 100755
+
99
−
0
View file @
33a14f9d
#!/usr/bin/perl
=head1 USAGE
cat data.json-lines | ./json2tsv.pl
Reads individual lines which *each* contain a separate json structure
and saves the data in TSV format.
This is useful to save data from MongoDB find() statement using
cut'n'paste.
=cut
use
strict
;
use
Data::
Dumper
;
$
Data::Dumper::
Indent
=
1
;
use
JSON
;
use
Util::
tsv
;
my
@PARS
;
my
$arg
;
while
(
defined
(
$arg
=
shift
(
@ARGV
)))
{
if
(
$arg
eq
'
--
')
{
push
(
@PARS
,
@ARGV
);
@ARGV
=
();
}
elsif
(
$arg
=~
/^--(.+)/
)
{
my
(
$opt
,
$val
)
=
split
('
=
',
$
1
,
2
);
if
(
$opt
eq
'
help
')
{
usage
();
}
else
{
usage
();
}
}
elsif
(
$arg
=~
/^-(.+)/
)
{
foreach
my
$opt
(
split
('',
$
1
))
{
if
(
$opt
eq
'
h
')
{
usage
();
exit
(
0
);
}
elsif
(
$opt
eq
'
x
')
{
$x_flag
=
1
;
}
else
{
usage
();
}
}
}
else
{
push
(
@PARS
,
$arg
);
}
}
my
$x
=
parse_stream
(
*STDIN
);
# print "x: ", Dumper ($x);
$x
->
save_tsv
('
data.tsv
');
exit
(
0
);
sub
parse_stream
{
local
*F
=
shift
;
my
@rows
;
my
%columns
;
LINE:
while
(
my
$l
=
<
F
>
)
{
chop
;
next
LINE
unless
(
$l
);
# print ">> l=[$l]\n";
my
$data
;
eval
{
$data
=
from_json
(
$l
);
};
if
(
$@
)
{
print
"
error:
",
$@
,
"
\n
";
next
LINE
;
}
# print "data: ", Dumper ($data);
push
(
@rows
,
$data
);
foreach
my
$e
(
keys
%$data
)
{
$columns
{
$e
}
++
;
}
}
my
$cols
=
[
sort
keys
%columns
];
my
$res
=
new
Util::
tsv
('
data
',
$cols
);
# print "res: ", Dumper ($res);
$res
->
{
rows
}
=
\
@rows
;
$res
;
}
__END__
=head1 TODO
* option to specify output filename
* option to specify column names in their expected order
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