Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • shell script for copying files with consecutive numbers

    Hi all,

    I have 170 fastq files from miSeq. They are named as 1_Sxx_L001…, 2_Sxx_L001…, 3_Sxx_L001… consecutively.

    If I only need files from 1 to 120. How to quickly copy those files? I was thinking about using a for loop, but keep getting errors.

    I can try this, but inefficient and error prone.
    cp [1-9]_*.gz;
    cp [1-9][0-9]_*.gz;
    cp [1-9][0-1][0-9]_*.gz;
    cp 120.*gz

    thanks in advance.

    example file names:

    100_S122_L001_R1_001.fastq.gz 126_S145_L001_R2_001.fastq.gz 152_S168_L001_R1_001.fastq.gz 23_S71_L001_R2_001.fastq.gz 4_S36_L001_R1_001.fastq.gz 75_S34_L001_R2_001.fastq.gz
    100_S122_L001_R2_001.fastq.gz 127_S155_L001_R1_001.fastq.gz 152_S168_L001_R2_001.fastq.gz 24_S82_L001_R1_001.fastq.gz 4_S36_L001_R2_001.fastq.gz 76_S45_L001_R1_001.fastq.gz
    Last edited by JQL; 10-17-2017, 08:02 AM.

  • #2
    Where are you copying them from or to?

    You can generate the numbers you need using a bash for loop like this easily
    Code:
    for i in `seq 1 120`; do echo $i; done

    Comment


    • #3
      Those files belong to 3 projects. Lets say I want to copy the 120 files to the directory called project1.

      for i in `seq 1 120`
      do
      cp "$1_*.fastq.gz" ~/project1/ ## it doesn't work.
      done

      thanks

      Originally posted by GenoMax View Post
      Where are you copying them from or to?

      You can generate the numbers you need using a bash for loop like this easily
      Code:
      for i in `seq 1 120`; do echo $i; done

      Comment


      • #4
        That should be a $i (not 1).
        Code:
        for i in `seq 1 120`
        do
        cp $i\_*.fastq.gz ~/project1/
        done
        Last edited by GenoMax; 10-17-2017, 08:38 AM. Reason: Escaped _

        Comment


        • #5
          how come I copied all 170 files (since they are PE, so 340) over? Should be 240. Was it to due the "_"?

          $ for i in `seq 1 120`; do cp $i_*fastq.gz ~/project1/; done

          $ ls |wc -l
          340

          Comment


          • #6
            The _ should have been escaped. Corrected code above. Replace "echo" instead of "cp" to make sure all looks good first.
            Last edited by GenoMax; 10-17-2017, 08:44 AM.

            Comment


            • #7
              yes, it was the "_".

              thanks!

              $ ls | wc -l
              240

              Comment


              • #8
                what does underscore mean without escaped?

                Originally posted by GenoMax View Post
                The _ should have been escaped. Corrected code above. Replace "echo" instead of "cp" to make sure all looks good first.

                Comment


                • #9
                  Run the following to see the difference
                  Code:
                  for i in `seq 1 120`
                  do
                  echo cp $i_*.fastq.gz ~/project1/
                  done

                  Comment


                  • #10
                    I ran it before. It copied all the *.gz files over (more than 2x120).
                    Interestingly, when I removed the copies in project1,
                    it copied again, removed, recopied.

                    any explanation?

                    Originally posted by GenoMax View Post
                    Run the following to see the difference
                    Code:
                    for i in `seq 1 120`
                    do
                    echo cp $i_*.fastq.gz ~/project1/
                    done

                    Comment

                    Latest Articles

                    Collapse

                    • 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
                    • seqadmin
                      Techniques and Challenges in Conservation Genomics
                      by seqadmin



                      The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                      Avian Conservation
                      Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                      03-08-2024, 10:41 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by seqadmin, 03-27-2024, 06:37 PM
                    0 responses
                    13 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 03-27-2024, 06:07 PM
                    0 responses
                    12 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 03-22-2024, 10:03 AM
                    0 responses
                    53 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 03-21-2024, 07:32 AM
                    0 responses
                    69 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X