Rename files based on their contents

Tonight I needed to rename a number of files based on their contents. Using this for loop it will rename all files in your current directory named xx*. The files will be named based on their first line’s third column:

for i in xx*; do j=`head -1 $i| awk -F, ‘{print $3}’`; mv “$i” “$j”; done

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *