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
                      Essential Discoveries and Tools in Epitranscriptomics
                      by seqadmin




                      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
                      Yesterday, 07:01 AM
                    • 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

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

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