Thursday, 5 November 2009

Perl one liner: Rename a file with some of its contents

I had some microarrays files that the scanner had named something not very useful. I wanted them renamed with their chip barcode which was in side the file.

perl -ne '`mv $ARGV $1.txt` if m/(1234567890(\d+_\d+_\d+))/;' *.txt

This little one liner does just that. The current file name is stored in $ARGV by default then I simply rename it from that to the extracted text I want.

No comments:

Post a Comment