Entering edit mode
3.9 years ago
Nobody
▴
30
Hi!
i have a multiple tsv files, do you have any methods to merge them in a single file with only header ?
Hi!
i have a multiple tsv files, do you have any methods to merge them in a single file with only header ?
I think this will work for you. Python code to merge tsv files in to one with only header.
#merge_tsv_files
from glob import glob
filename = 'merge.tsv'
with open(filename, 'a') as singleFile:
first_tsv = True
for tsv in glob('*.tsv'):
if tsv == filename:
pass
else:
header = True
for line in open(tsv, 'r'):
if first_tsv and header:
singleFile.write(line)
first_tsv = False
header = False
elif header:
header = False
else:
singleFile.write(line)
singleFile.close()
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
or if your header is at the top after a sort
cat file*.txt |sort | uniq > merged.txt
i want to do it with python
use tsv-append and a simple header aware concatenation is (copy/pasted):
All the available options can be read from here: https://github.com/eBay/tsv-utils/blob/master/docs/tool_reference/tsv-append.md
it works with python ?
hard to know what exactly you have and what you want, you can use
cat
to concatenate filesif you need to merged them (column-wise , we don't have enough info to figure that out), have a look at the linux
paste
command