Batch Rename files using CSV list

Discussion in 'Mac Programming' started by diddykiddy, Jan 6, 2014.

  1. diddykiddy macrumors newbie

    Jan 4, 2008

    I would be grateful if anyone can help me with a batch renaming issue;

    I create 50+ page PDF files with individual pages intended for each person, so what I need to do ideally is create individual pdf files as follows;

    source > feedback.pdf and filenames.csv

    etc ..

    I can easily create a CSV file of filenames I need, I can easily split the source PDF into individual pages using Acrobat Pro - all I need now is a fast way to rename the files, ideally without faffing about with full POSIX file path lists?

    I have used renamed and a better finder rename before but anyone recommend an up to date tool for OSX 10.8.4 and/or Mountain Lion?

    I have to do this 5+ times over the course of a year - it get tedious ! I am a little comfortable with command line, never really used automator with any success but open to ideas

    thanks for any advice - gratefully received:)


  2. MacUser2525 macrumors 68000


    Mar 17, 2007
    Depending on how the .pdf individual files get named when saving them a simple bash script should do you. If they are named sequentially like 01.pdf, 02.pdf ... and they are always done in the same order for the people involved ie. john-smith-feedback.pdf is the 01, jane-smith-feedback.pdf is 02 then a bash script like this executed in the directory containing the .pdf will do you.

    mv 01.pdf john-smith-feedback.pdf
    mv 02.pdf jane-smith-feedback.pdf
  3. subsonix macrumors 68040

    Feb 2, 2008
    You have a folder with a lot of pdf documents, named in an obscure way. You also have a csv file with these names and the preferred new names occurring as comma separated pairs, one per line?

    You would like to rename the files according to the csv file? Can you provide a line from the csv file as an example?

    This is quite important, or we will end up giving you examples that doesn't work and post back and forth for one page before you show the actual data.

    Based on what you have said it's very easy to do in the terminal. Just make sure you back up any data that is valuable as commands such as mv has the potential to destroy lots of data in a short amount of time if you use a loop. :D

    First of all, put your pdf files and your csv file into a new folder with nothing else in it. Then navigate to the folder in the terminal. After that you make a loop that separates the values and renames the files accordingly, as an example:

    while read line
       doc=$(echo "$line" | awk -F"," '{print $1}')
       name=$(echo "$line" | awk -F"," '{print $2}')
       mv "$doc" "$name"
    done < names.csv
  4. chown33 macrumors 604

    Aug 9, 2009
    So many bees
    I wholeheartedly agree with this.

    Since awk automatically loops for every line in a file, a simpler (untested) version might be something like:
    awk -F "," '{ system( "mv " $1 " " $2 ) }' names.csv
    In other words, let awk do the per-line looping implicitly, and have it use system() to execute the mv command. (I probably neglected some quoting in the mv cmd shown.)
  5. diddykiddy thread starter macrumors newbie

    Jan 4, 2008
    thanks - will try


    thanks for your ideas, I'll give them a try a little later today, have to brush up on my bash scripting a little. Should have some time after lunch

    incidentally what I'm doing to create the pdf is using an excel csv file in InDesign to create a batch of pages based on a template, so I have a bunch of variables (<<firstname>>, <<lastname>>, <<grade>>) and the csv file fills them all in on each page. If there were only a way to get Indesign to name each page from the variables . . . a challenge for another day.

    If anyone wants to know more about the indesign merge thingy I'd be happy to share

    thanks, happy new year !


Share This Page