Overview

This page is designed to give minor examples, and general principles for renaming multiple files at once from the command line based on given criteria and wildcards. Makes use of a command line for loop and the sed command.

Renaming multiple fastq files

  1. Assume you have downloaded multiple fastq files which are of format: Samplename-Lane-runID-etc-etc.fastq ... the following command will rename all files to Samplename.fastq.
  2. for f in *.fastq;do new_name=$(echo $file|sed 's/-*/.fastq/'); mv -i $file $new_name;done
    • Generic explanation in parts:
    • for f in *.fastq;
      • "for" is the start of a for loop which allows you to do the same thing to multiple files sequentially
      • generate a generic variable named "f" which is a list of all files in the current directory that end in ".fastq"
    • do new_name=$(echo $file|
      • do is what you want to do with each of the entries in the for loop
      • generate a new variable named "new name" with the starting point of the old file name, change the name based on the following sed command.

    • do "new variable name"=$(echo $"variable name"|sed 's/what to find/what to replace/');mv $"new variable name" $"variable name";done

-- Main.DanielDeatherage - 21 Aug 2014

Edit | Attach | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions...

 Barrick Lab  >  WebLeftBar  >  ComputationList  >  ProtocolsMassRename

Topic revision: r3 - 27 Aug 2014 - 17:08:45 - Main.DanielDeatherage
 
This site is powered by the TWiki collaboration platformCopyright ©2017 Barrick Lab contributing authors. Ideas, requests, problems? Send feedback