Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robelb4
    Member
    • Jul 2011
    • 10

    #1

    perl -reading from 2 files and merge them

    Hi All,

    I just want read 2 files and write their result (3 lines from each file at time) in another file, how do i do it in perl?? thanks

    example:
    file1.txt content file2.txt content

    > zzzzzzzzzzzzzzz >aaaaaaaaaaaaaa
    xxxxxxxxxxxxxxxxx bbbbbbbbbbbbb
    vvvvvvvvvvvvvv cccccccccccccc
    > sssssssssssssss > 1111111111111
    mmmmmmmmmm 2222222222222
    nnnnnnnnnnnnnn 3333333333333

    output.txt content should be

    > zzzzzzzzzzzzzzz
    xxxxxxxxxxxxxxxxx
    vvvvvvvvvvvvvv
    >aaaaaaaaaaaaaa
    bbbbbbbbbbbbb
    cccccccccccccc
    > sssssssssssssss
    mmmmmmmmmm
    nnnnnnnnnnnnnn
    > 1111111111111
    222222222222222
    33333333333333
  • robelb4
    Member
    • Jul 2011
    • 10

    #2
    by the way the 2 files i put side by side is just two show they're the same format.

    thanks

    Comment

    • damiankao
      Member
      • Jan 2010
      • 49

      #3
      do you just want to merge two fasta files together? you can just use the 'cat' linux command for that. So something like this:

      cat fastaA.fa fastaB.fa > mergedFasta.fa

      Comment

      • robelb4
        Member
        • Jul 2011
        • 10

        #4
        Originally posted by damiankao View Post
        do you just want to merge two fasta files together? you can just use the 'cat' linux command for that. So something like this:

        cat fastaA.fa fastaB.fa > mergedFasta.fa
        Not like that, it should be 3 lines at a time, as I said it above

        Comment

        • EHC
          Member
          • Jun 2010
          • 11

          #5
          use paste

          PASTE(1) BSD General Commands Manual PASTE(1)

          NAME
          paste -- merge corresponding or subsequent lines of files

          SYNOPSIS
          paste [-s] [-d list] file ...

          DESCRIPTION
          The paste utility concatenates the corresponding lines of the given input files, replacing all but the last file's newline characters with a single tab character, and writes the
          resulting lines to standard output. If end-of-file is reached on an input file while other input files still contain data, the file is treated as if it were an endless source of
          empty lines.

          The options are as follows:

          Comment

          • kmcarr
            Senior Member
            • May 2008
            • 1181

            #6
            Originally posted by robelb4 View Post
            Hi All,

            I just want read 2 files and write their result (3 lines from each file at time) in another file, how do i do it in perl?? thanks

            example:
            Code:
            file1.txt content              file2.txt content
            
            > zzzzzzzzzzzzzzz                     >aaaaaaaaaaaaaa
            xxxxxxxxxxxxxxxxx                     bbbbbbbbbbbbb
            vvvvvvvvvvvvvv                        cccccccccccccc
            > sssssssssssssss                     > 1111111111111
            mmmmmmmmmm                            2222222222222
            nnnnnnnnnnnnnn                        3333333333333
             
            output.txt content should be
            
            > zzzzzzzzzzzzzzz
            xxxxxxxxxxxxxxxxx
            vvvvvvvvvvvvvv 
            >aaaaaaaaaaaaaa
            bbbbbbbbbbbbb
            cccccccccccccc
            > sssssssssssssss 
            mmmmmmmmmm  
            nnnnnnnnnnnnnn  
            > 1111111111111
            222222222222222
            33333333333333
            (Using CODE tags around text you want to present in a formatted manner helps with readability.)

            A few questions:

            Are the two files you want to merge FASTA files? I'm guessing because of the ">" at the beginning of each block of text. Also, are there really spaces between the ">" and the character following it?

            Can you be absolutely positive that every block is exactly 3 lines long?

            Can you be absolutely positive that there are exactly the same number of text blocks in each file?

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
              by SEQadmin2



              Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

              Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
              ...
              10-14-2026, 09:55 AM
            • SEQadmin2
              New Genomics Technologies Take Aim at Long-Standing Limits
              by SEQadmin2


              Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

              We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
              ...
              09-28-2026, 10:25 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 10-22-2026, 11:13 AM
            0 responses
            23 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-22-2026, 10:48 AM
            0 responses
            20 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-15-2026, 10:52 AM
            0 responses
            36 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-14-2026, 05:39 AM
            0 responses
            42 views
            0 reactions
            Last Post SEQadmin2  
            Working...