I have two files, one large text file with multiple columns, in a similar format as the following:
Col1 Col2 A B C D G H I L N Q S ...
1 0 1 0 1 0 1 0 1 0 1 0 1 ...
0 2 1 0 0 0 0 0 2 1 2 3 4 ...
...
and a text file with columns to match in
Col1
Col2
Col3
B
D
F
...
(note that some lines in this file may not match the column titles in the large tsv file)
I want to cut the large file based on column titles which match those given in the file (ignoring those in the column title or the text file which do not match, so the output file column titles start Col1 Col2 B D ...
)
Is there an easy way of doing this rather than looping over each line in the second text file and building a file using paste
?
This is on Mac OS X, so using ksh
, although pure bash
could be used instead.