Jan 282013
 

When doing loops and renaming files it is very important to able to strip the end of the original filename off. Otherwise you quickly end up with long and awkward filenames like “ZF_rnaseq.bed.gz.processed.uniques.gz”

for i in *.bed.gz; do zcat $i | cut -f1 | gzip -f  > ${i%.bed.gz}.cut.gz; done

The ${variable%.end_of_filename_you_want_remove}.new_file_name syntax is easy to use and easy to forget.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)