Bulk rename files in Mac with specific pattern using CSV file

mac bulk rename specific pattern

I was working on a project to restore over 3000 course files into a LMS system. However the file name I got does not follow the required name format. Mac has built in bulk rename feature (select all files and right click to rename). This only allow search and replace or format the file name.

However you cant remove several delimited content or create your own format of file name. So here is the solution how to bulk rename files in any pattern you need using excel CSV.

Step 1

Create excel CSV with old name and new name delimited with a semicolon.

mac bulk rename specific pattern

As you can see above, the old name is 2918-abc1234-20190116-1400-nu.mbz. And the new name I need is abc1234.mbz. You can use Excel text to column function and Concatenate() function to split the name and combine it with ; Note both new and old name is in column A and delimited with a semicolon. Save this file as myfile.csv

Step 2

Place myfile.csv and all files in one folder. Open terminal in mac and run the following commands;

cd /myfolder
perl -pi -e 's/\r\n/\n/;' myfile.csv
while IFS=\; read old new; do mv "$old" "$new"; done < myfile.csv