0

This question already has an answer here:

I have huge file 100M, that has the text (few lines below,) stack of lines are unique scaffold1_, scaffold2_ and on.

I would like to have a new file that is specific to each scaffold.1...txt tried few sed and grep commands but they didn't help.

scaffold1_2,C,C,C,C,N,C,N,C,G,G,C,N,C,C,G,N,N,C,G,N,C,C,C,G,C,N,N,C,C
scaffold1_113,T,T,T,T,T,T,T,T,T,C,T,T,T,T,T,T,C,T,T,T,T,T,C,T,T,N,T,T,T
scaffold1_149,G,G,G,G,C,G,C,G,C,G,G,C,C,G,C,C,G,C,G,G,C,G,G,G,G,C,G,G,G
scaffold1_160,G,G,G,T,G,T,T,T,N,T,T,T,G,T,G,G,T,T,T,T,T,N,T,T,G,G,T,T,G
scaffold2_315,C,C,C,G,C,C,C,C,C,C,C,G,C,C,G,G,G,C,C,C,C,C,C,G,C,C,C,C,G
scaffold2_318,G,A,A,A,A,A,A,G,A,A,A,A,A,A,A,A,A,A,G,A,A,A,A,A,A,A,A,A,A
scaffold2_323,T,T,T,T,T,C,C,T,T,T,T,T,T,T,T,T,T,T,T,C,T,T,T,T,T,T,T,T,T
scaffold2_397,A,A,A,A,A,A,C,A,A,A,A,A,A,A,A,A,C,A,A,A,A,A,A,A,A,A,A,A,A
scaffold3_402,C,C,C,C,C,T,C,C,C,C,C,C,C,T,C,C,C,T,C,C,C,C,C,C,C,C,C,C,C
scaffold3_465,G,G,G,G,G,G,G,G,G,C,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,C,C,G
scaffold3_502,C,C,C,C,C,C,C,C,C,G,C,C,C,C,C,C,C,G,C,G,C,G,C,C,C,C,C,C,C
scaffold3_508,G,G,G,C,G,G,G,G,G,C,G,C,C,C,C,C,G,C,G,C,G,C,C,C,C,C,C,C,C
scaffold3_533,G,G,G,G,A,A,A,G,A,G,A,G,G,A,G,G,A,A,G,A,A,G,G,G,G,G,G,G,G
scaffold4_555,T,T,T,T,T,T,T,T,T,T,T,T,T,T,A,A,T,T,T,T,T,T,T,T,T,T,T,T,T
scaffold4_586,T,T,T,T,T,T,T,T,T,T,T,C,C,T,T,T,T,T,T,T,T,T,C,T,C,T,T,T,T
scaffold4_593,A,G,G,G,A,A,A,A,G,G,A,A,A,A,G,G,A,A,G,A,G,G,A,G,A,G,A,A,G
scaffold4_598,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,A,A,C
scaffold4_664,G,A,A,G,G,G,A,G,G,G,G,G,G,G,G,G,A,G,G,G,G,G,G,G,G,G,G,G,G
scaffold5_667,C,C,C,C,C,C,C,C,T,C,C,C,C,C,C,C,C,C,T,C,T,T,C,C,C,C,T,T,C
scaffold5_670,A,A,A,A,A,A,A,A,G,A,A,A,A,A,A,A,A,A,G,A,G,G,A,A,A,A,G,G,A
scaffold5_679,T,C,C,C,C,C,C,T,C,T,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C

resulting files should look something like

cat scaffold1.txt
scaffold1_2,C,C,C,C,N,C,N,C,G,G,C,N,C,C,G,N,N,C,G,N,C,C,C,G,C,N,N,C,C
scaffold1_113,T,T,T,T,T,T,T,T,T,C,T,T,T,T,T,T,C,T,T,T,T,T,C,T,T,N,T,T,T
scaffold1_149,G,G,G,G,C,G,C,G,C,G,G,C,C,G,C,C,G,C,G,G,C,G,G,G,G,C,G,G,G
scaffold1_160,G,G,G,T,G,T,T,T,N,T,T,T,G,T,G,G,T,T,T,T,T,N,T,T,G,G,T,T,G
cat scaffold2.txt
scaffold2_315,C,C,C,G,C,C,C,C,C,C,C,G,C,C,G,G,G,C,C,C,C,C,C,G,C,C,C,C,G
scaffold2_318,G,A,A,A,A,A,A,G,A,A,A,A,A,A,A,A,A,A,G,A,A,A,A,A,A,A,A,A,A
scaffold2_323,T,T,T,T,T,C,C,T,T,T,T,T,T,T,T,T,T,T,T,C,T,T,T,T,T,T,T,T,T
scaffold2_397,A,A,A,A,A,A,C,A,A,A,A,A,A,A,A,A,C,A,A,A,A,A,A,A,A,A,A,A,A

marked as duplicate by don_crissti, Jeff Schaller, Community Feb 11 '16 at 14:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • what grep command did you try? grep ^scaffold1_ hugefile looks like it would do what you want – Jeff Schaller Feb 11 '16 at 14:40
  • @JeffSchaller i tried like this and it works, but i have around 1600 scaffolds grep "^scaffold2_" finalsnp-hscan-29iso.txt > scaffold2test.txt. – kapr0001 Feb 11 '16 at 14:47
  • @don_crissti sorry i just realised it have a posted similar question long back. but i was't success before. – kapr0001 Feb 11 '16 at 14:48
1
for i in $(cat myfile.txt|cut -d"_" -f 1 | sort | uniq)
do
  grep ${i} myfile.txt > ${i}.txt
done

This should work

  • You should grep on the pattern ^${i}_ – doneal24 Feb 11 '16 at 14:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.