Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • JQL
    Member
    • Apr 2011
    • 83

    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.
  • GenoMax
    Senior Member
    • Feb 2008
    • 7142

    #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

    • JQL
      Member
      • Apr 2011
      • 83

      #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

      • GenoMax
        Senior Member
        • Feb 2008
        • 7142

        #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

        • JQL
          Member
          • Apr 2011
          • 83

          #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

          • GenoMax
            Senior Member
            • Feb 2008
            • 7142

            #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

            • JQL
              Member
              • Apr 2011
              • 83

              #7
              yes, it was the "_".

              thanks!

              $ ls | wc -l
              240

              Comment

              • JQL
                Member
                • Apr 2011
                • 83

                #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

                • GenoMax
                  Senior Member
                  • Feb 2008
                  • 7142

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

                  Comment

                  • JQL
                    Member
                    • Apr 2011
                    • 83

                    #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

                    • SEQadmin2
                      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                      by SEQadmin2



                      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                      ...
                      07-09-2026, 11:10 AM
                    • SEQadmin2
                      Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                      by SEQadmin2



                      Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                      There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                      07-08-2026, 05:17 AM
                    • GATTACAT
                      Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                      by GATTACAT
                      Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                      07-01-2026, 11:43 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, 07-13-2026, 10:26 AM
                    0 responses
                    25 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-09-2026, 10:04 AM
                    0 responses
                    35 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-08-2026, 10:08 AM
                    0 responses
                    22 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-07-2026, 11:05 AM
                    0 responses
                    34 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...