0

I would like to merge two files into a new one but two lines by two. my two files looks like this:

File 1

'>dog-001  
atcatctatctat  
'>dog-002  
atcgatcgatctact  

File 2

'>cat-001  
atctgtctacta  
'>cat-002  
atctgtatfga  

Output

'>dog-001  
atcatctatctat  
'>cat-001  
atctgtctacta    
'>dog-002  
atcgatcgatctact  
'>cat-002  
atctgtatfga  

I have tried some command with AWK and paste but I dont know how to indicate to take 2 lines.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Nico64
  • 161
  • 9
  • Show us your attempt, it will help us see how much you already know and where exactly you are stuck. – tripleee Feb 16 '18 at 12:48
  • As such, I don't think Awk is ideal for this particular scenario. – tripleee Feb 16 '18 at 12:48
  • Is there a reason your files are *almost* FASTA format? – tripleee Feb 16 '18 at 12:49
  • The proposed duplicate has a pretty nice Awk solution, it should not be hard to adapt that to read two lines instead of one. – tripleee Feb 16 '18 at 12:51
  • I have tried with awk: awk '(NR%2){print; getline < "file2"; print}' file1 > newfile and paste paste -d \\n *.files > newfiles yes its fasta format, with seq in the same order. – Nico64 Feb 16 '18 at 13:26
  • You have to adapt the code to read two lines from each. I don't think you can do that with `paste` but the change to the Awk script should be easy even if you are only just learning Awk – tripleee Feb 16 '18 at 13:30
  • The single quotes before `>` are not allowed in FASTA proper as far as I remember the spec. – tripleee Feb 16 '18 at 13:30
  • 1
    More like: `awk '1;!(NR%2){for(i=1;i<=2;i++){getline < "file2"; print}}' file1` Just modified your nonworking solution and did not bother to add the `ìf` before the `getline`. – James Brown Feb 16 '18 at 13:33
  • thanks for answer. Yes for single quote it was beacause of format of the website... – Nico64 Feb 16 '18 at 13:34
  • Thanks for the comments. You have indicated that's it is a duplicate, how can I access to the existing question? – Nico64 Feb 16 '18 at 13:36
  • @Nico64 Link is on the top. – James Brown Feb 16 '18 at 13:36
  • 1
    Ho yes sorry. That was the one I was already looking for idea. – Nico64 Feb 16 '18 at 13:39

0 Answers0