-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader
More file actions
executable file
·95 lines (69 loc) · 2.17 KB
/
header
File metadata and controls
executable file
·95 lines (69 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env perl
# header - Show column headers in a file with position and example values
#
# written by Phillip Dexheimer (pdexheimer@gmail.com), 2019
# based on a Python script by Krishna Roskin
#
use Getopt::Long;
use Pod::Usage;
# Standard module in perl - the parse_line function handles quoted delimiters
use Text::ParseWords;
my $delim = "\t";
my $lines = 0;
my $start = 1;
my $zero_start = 0;
my $help = '';
GetOptions("delim=s" => \$delim,
"num-examples=i" => \$lines,
"zero-start|0+" => \$zero_start,
"start=i" => \$start,
"help|?" => \$help) or pod2usage(2);
pod2usage(-verbose => 1, -exitval => 1) if ($help);
my $start_idx = !$zero_start;
my @header = ();
my @examples = ();
my $ncols = undef;
my $n_examples = 0;
while (<>) {
next if $. < $start;
chomp;
if (@header == 0) {
@header = parse_line($delim, 0, $_);
} else {
last if $n_examples >= $lines;
my @F = parse_line($delim, 0, $_);
for my $i (0..$#F) {
push @{$examples[$i]}, $F[$i];
}
$n_examples++;
}
}
for my $i (0..$#header) {
printf("%7d\t%s\n", $i+$start_idx, $header[$i]);
print map { "\t$_\n" } @{$examples[$i]};
print "\n";
}
__END__
=head1 NAME
header - Show the column headers of a file with position and (optionally) example data values
=head1 SYNOPSIS
header [OPTIONS] [FILE]
Options:
-d, --delim DELIM Specifies the column delimiter (default <TAB>)
-n, --num-examples COUNT How many data values to show (default 0)
-s, --start LINENUM What line to start with? (default 1)
-0, --zero-start If specified, column indices are 0-based rather than 1-based
-?, -h, --help Print a help message
If FILE is not specified on the command line (or is -), standard input will be read
=head1 OPTIONS
=over 4
=item B<--delim>
The delimiter may be present within a column if it is backslash-escaped (ie, \,)
=item B<--num-examples>
How many lines of input after the header should be parsed and displayed as examples (default 0)
=item B<--start>
Start at this line - useful if the matrix includes comment or header lines
=item B<--zero-start>
Specify this to start numbering headers at 0 instead of 1
=back
=cut