notes on evolutionary biology papers/programs and other stuff: a non-frequent approach

Monday, June 18, 2007

rename it with a script

Although there are nice little programs for OSX that rename file names and extensions, like Renamer4Mac, NameChanger and FileSorter, it's always good to have something simple handy, like a script.

in AppleScript: Nem

in Perl: here and here (Linux)

my favorite is a loop in Unix to rename file extensions:

1) if you know what your extensions are:


#!/bin/bash

for i in *fasta
do
mv "$i" "`echo $i | sed -e 's/fasta/fas/'`"
done

for i in *fas
do
cat "$i" | sed -e 's/\.fasta\"/\.fas\"/g' > out
mv out "$i"
done


2) if you prefer an interactive script that will ask you what extension names you want to change from/to:


#!/bin/bash

echo -n "enter old: "
read old
echo -n "enter new: "
read new

for i in *.$old
do
mv "$i" "`echo $i | sed -e "s/$old/$new/"`"
done


The shell scripts were kindly written by my friend Ricardo Baratto