Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

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

    thanks

    Comment


    • #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


      • #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


        • #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


          • #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

            • seqadmin
              Current Approaches to Protein Sequencing
              by seqadmin


              Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
              04-04-2024, 04:25 PM
            • seqadmin
              Strategies for Sequencing Challenging Samples
              by seqadmin


              Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
              03-22-2024, 06:39 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, 04-11-2024, 12:08 PM
            0 responses
            25 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 10:19 PM
            0 responses
            27 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 09:21 AM
            0 responses
            24 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-04-2024, 09:00 AM
            0 responses
            52 views
            0 likes
            Last Post seqadmin  
            Working...
            X