Unconfigured Ad

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

    #1

    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
                      Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                      by SEQadmin2



                      CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                      Despite this, “CRISPR helped turn genome editing from a specialized technique into
                      ...
                      Today, 11:01 AM
                    • SEQadmin2
                      Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                      by SEQadmin2


                      Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                      The systematic characterization of the human proteome has
                      ...
                      07-20-2026, 11:48 AM
                    • 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

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, Today, 02:55 AM
                    0 responses
                    6 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    11 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-23-2026, 11:41 AM
                    0 responses
                    12 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-20-2026, 11:10 AM
                    0 responses
                    24 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...