Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

diddykiddy

macrumors newbie
Original poster
Jan 4, 2008
28
2
Hi

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

destination>
john-smith-feedback.pdf
jane-smith-feedback.pdf
billy-whizz-feedback.pdf
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:)

cheers

Dave
 
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.

Code:
#!/bin/bash
mv 01.pdf john-smith-feedback.pdf
mv 02.pdf jane-smith-feedback.pdf
...
 
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:

Code:
while read line
do
   doc=$(echo "$line" | awk -F"," '{print $1}')
   name=$(echo "$line" | awk -F"," '{print $2}')
   mv "$doc" "$name"
done < names.csv
 
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.

I wholeheartedly agree with this.


Code:
while read line
do
   doc=$(echo "$line" | awk -F"," '{print $1}')
   name=$(echo "$line" | awk -F"," '{print $2}')
   mv "$doc" "$name"
done < names.csv
Since awk automatically loops for every line in a file, a simpler (untested) version might be something like:
Code:
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.)
 
thanks - will try

hi

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 !

D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.