1TABMERGE(1) User Contributed Perl Documentation TABMERGE(1)
2
3
4
6 tabmerge - unify delimited files on common fields
7
9 tabmerge [action] [options] file1 file2 [...]
10
11 Actions:
12
13 --min Take only fields present in all files [DEFAULT]
14 --max Take all fields present
15 -f⎪--fields=f1[,f2] Take only the fields mentioned in the
16 comma-separated list
17
18 Options:
19
20 -l⎪--list List available fields
21 --fs=x Use "x" as the field separator
22 (default is tab "\t")
23 --rs=x Use "x" as the record separator
24 (default is newline "\n")
25 -s⎪--sort=f1[,f2] Sort data ASCII-betically on field(s)
26 --stdout Print data in original delimited format
27 (i.e., not in a table format)
28
29 --help Show brief help and quit
30 --man Show full documentation
31
33 This program merges the fields -- not the rows -- of delimited text
34 files. That is, if several files are almost but not quite entirely
35 unlike each other in their structure (in their field names, numbers or
36 orders), this script allows you to easily unify the files into one file
37 with all the same fields. The output can be based on fields as deter‐
38 mined by the three "action" flags.
39
40 For the following examples, consider three files that contain the fol‐
41 lowing fields:
42
43 +------------+---------------------------------+
44 ⎪ File ⎪ Fields ⎪
45 +------------+---------------------------------+
46 ⎪ merge1.tab ⎪ name, type, position ⎪
47 ⎪ merge2.tab ⎪ name, type, position, lod_score ⎪
48 ⎪ merge3.tab ⎪ name, position ⎪
49 +------------+---------------------------------+
50
51 To list all available fields in the files and the number of times they
52 are present:
53
54 $ tabmerge --list merge*
55 +-----------+-------------------+
56 ⎪ Field ⎪ No. Times Present ⎪
57 +-----------+-------------------+
58 ⎪ lod_score ⎪ 1 ⎪
59 ⎪ name ⎪ 3 ⎪
60 ⎪ position ⎪ 3 ⎪
61 ⎪ type ⎪ 2 ⎪
62 +-----------+-------------------+
63
64 To merge the files on the minimum overlapping fields:
65
66 $ tabmerge merge*
67 +----------+----------+
68 ⎪ name ⎪ position ⎪
69 +----------+----------+
70 ⎪ RM104 ⎪ 2.30 ⎪
71 ⎪ RM105 ⎪ 4.5 ⎪
72 ⎪ TX5509 ⎪ 10.4 ⎪
73 ⎪ UU189 ⎪ 19.0 ⎪
74 ⎪ Xpsm122 ⎪ 3.3 ⎪
75 ⎪ Xpsr9556 ⎪ 4.5 ⎪
76 ⎪ DRTL ⎪ 2.30 ⎪
77 ⎪ ALTX ⎪ 4.5 ⎪
78 ⎪ DWRF ⎪ 10.4 ⎪
79 +----------+----------+
80
81 To merge the files and include all the fields:
82
83 $ tabmerge --max merge*
84 +-----------+----------+----------+--------+
85 ⎪ lod_score ⎪ name ⎪ position ⎪ type ⎪
86 +-----------+----------+----------+--------+
87 ⎪ ⎪ RM104 ⎪ 2.30 ⎪ RFLP ⎪
88 ⎪ ⎪ RM105 ⎪ 4.5 ⎪ RFLP ⎪
89 ⎪ ⎪ TX5509 ⎪ 10.4 ⎪ AFLP ⎪
90 ⎪ 2.4 ⎪ UU189 ⎪ 19.0 ⎪ SSR ⎪
91 ⎪ 1.2 ⎪ Xpsm122 ⎪ 3.3 ⎪ Marker ⎪
92 ⎪ 1.2 ⎪ Xpsr9556 ⎪ 4.5 ⎪ Marker ⎪
93 ⎪ ⎪ DRTL ⎪ 2.30 ⎪ ⎪
94 ⎪ ⎪ ALTX ⎪ 4.5 ⎪ ⎪
95 ⎪ ⎪ DWRF ⎪ 10.4 ⎪ ⎪
96 +-----------+----------+----------+--------+
97
98 To merge and extract just the "name" and "type" fields:
99
100 $ tabmerge -f name,type merge*
101 +----------+--------+
102 ⎪ name ⎪ type ⎪
103 +----------+--------+
104 ⎪ RM104 ⎪ RFLP ⎪
105 ⎪ RM105 ⎪ RFLP ⎪
106 ⎪ TX5509 ⎪ AFLP ⎪
107 ⎪ UU189 ⎪ SSR ⎪
108 ⎪ Xpsm122 ⎪ Marker ⎪
109 ⎪ Xpsr9556 ⎪ Marker ⎪
110 ⎪ DRTL ⎪ ⎪
111 ⎪ ALTX ⎪ ⎪
112 ⎪ DWRF ⎪ ⎪
113 +----------+--------+
114
115 To merge the files on just the "name" and "lod_score" fields and sort
116 on the name:
117
118 $ tabmerge -f name,lod_score -s name merge*
119 +----------+-----------+
120 ⎪ name ⎪ lod_score ⎪
121 +----------+-----------+
122 ⎪ ALTX ⎪ ⎪
123 ⎪ DRTL ⎪ ⎪
124 ⎪ DWRF ⎪ ⎪
125 ⎪ RM104 ⎪ ⎪
126 ⎪ RM105 ⎪ ⎪
127 ⎪ TX5509 ⎪ ⎪
128 ⎪ UU189 ⎪ 2.4 ⎪
129 ⎪ Xpsm122 ⎪ 1.2 ⎪
130 ⎪ Xpsr9556 ⎪ 1.2 ⎪
131 +----------+-----------+
132
133 To do the same but mimic the original tab-delimited input:
134
135 $ tabmerge -f name,lod_score -s name --stdout merge*
136 name lod_score
137 ALTX
138 DRTL
139 DWRF
140 RM104
141 RM105
142 TX5509
143 UU189 2.4
144 Xpsm122 1.2
145 Xpsr9556 1.2
146
147 Why would you want to do this? Suppose you have several delimited text
148 files with nearly the same structure and want to create just one file
149 from them, but the fields may be in a different order in each file
150 and/or some files may contain more or fewer fields than others. (As
151 far-fetched as it may seem, it happens to the author more than he'd
152 like.)
153
155 * Text::RecordParser
156 * Text::TabularDisplay
157
159 Ken Youens-Clark <kclark@cpan.org>.
160
162 Copyright (C) 2006 Ken Youens-Clark. All rights reserved.
163
164 This program is free software; you can redistribute it and/or modify it
165 under the terms of the GNU General Public License as published by the
166 Free Software Foundation; version 2.
167
168 This program is distributed in the hope that it will be useful, but
169 WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
170 CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
171 Public License for more details.
172
173
174
175perl v5.8.8 2007-05-17 TABMERGE(1)