you meant
print >> $1".txt"
• 0 views
•
link
Hi, Please I have a big file with recombiantion rate for all chromosomes, and I need to split it by chromosome (1 to 22) than delete the first column (chromosome name) than store it in tab separated txt file, I am vzry beginner with bash, do you have any idea ? these is a sample from my file :
chr positions combrates Genetic_Map
23 151344121 3.6300873858 191.277343851358438
23 151344279 1.9852422405 191.277657519632442
23 151344318 0.8949795125 191.277692423833429
23 151345142 0.0757532087 191.277754844477414
thank you !
This is my preferred way of doing it.
awk 'BEGIN{FS="\t";OFS="\t"}{print > $1".txt"}' <input_file>
I am assuming that your data are tab-delimited. If that's not the case, change the FS and OFS accordingly. It will create files of the kind 23.txt based on your example.
you meant
print >> $1".txt"
print > $1".txt" works fine. But if you are planning to do this for multiple input files, print >> $1".txt" is the way to go.
$ cat temp.bed
chr1 100652477 100715409
chr11 175913961 176176380
chr1 150980972 151008189
chr11 6281252 6296044
chr1 20959947 20978004
chr11 32479294 32509482
chr1 27248212 27273362
chr11 31404352 31538564
chr1 36690016 36770957
chr11 46092975 46152302
$ awk 'BEGIN{FS="\t";OFS="\t"}{print > $1".txt"}' temp.bed
$ wc -l chr*.txt
5 chr11.txt
5 chr1.txt
Log in to answer this question.
Thank you all,
vkkodali method worked perfectly !
If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.

Thank you, I have already upvoted before you add your answer