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

The Mercurian

macrumors 68020
Original poster
Ok so here is the problem.

I have an archive of approx 6000 pdf's. At one point I ran OCR on them using adobe with the output saved to a new folder with files named PostOCR-filename.pdf
For some reason the folder of post OCR files is 12 files short of the original pdf file count.

I want to keep only one copy of all files. So basically I want to keep the PostOCR files, plus the 12 unknown files that weren't OCR'ed. The problem is - how do I identify those 12 files ?

I mean I could open 2 finder windows and drive myself demented manually searching for them - but I figure there must be a smarter way.

Anyone have any genius quick and easy ideas ?
 
Not afraid - I'd be willing to have a go at that.

I haven't really used it before in OSx, but back in the day I used to use linux/unix so I'm not afraid of command line stuff
 
Last edited:
Save this into a text file. Call it something like ~/Desktop/cleanup.sh

Code:
#!/bin/bash
mkdir ./deleteme
POSTPATH=./PostOCR
for pdf in *.pdf
do if [-f "$POSTPATH/PostOCR-$pdf"]
then
	mv -i $pdf deleteme/
fi

I assumed that the PostOCR files are in a subfolder of where the original files are. (modify if necessary).

open Terminal.app and make the originals folder your working directory.

Code:
cd ~/Documents/originals

then

Code:
source ~/Desktop/cleanup.sh

should collect all the dupes into the deleteme folder. Easy to wipe out then.

B
 
Ah fixed that problem but now I have another - I got 6000 of these
-bash: [-f: command not found

Edit: ok fixed that it just needed a space

It runs without complaining now and it creates the directory but it doesn't do anything else ?!
 
Last edited:
Did you modify POSTPATH appropriately or move those files to a subfolder of the originals path?

Are you sure about the post OCR filenames? If you didn't just prepend "PostOCR-" or the files are not in the right folder it won't work.

Can you post a sample of filenames with full path from the originals and PostOCR?

B
 
Hey no worries it works now.

I had a space in the directory name as in 'Post OCR'. So I took the space out and worked perfectly, leaving me with my 12 unidentified files now identified.

Thanks a million!!!! Much appreciated!!! Saved me work and I learned something!!!!!😀

----------

Can I ask you I understand the script except for one thing
for pdf in *.pdf
do if [-f "$POSTPATH/PostOCR-$pdf"]

in the 'for pdf' - is the first pdf an array name you are defining, or does it have some meaning in bash ?
and then is $pdf a member of the array ?
 
in the 'for pdf' - is the first pdf an array name you are defining, or does it have some meaning in bash ?
and then is $pdf a member of the array ?

Exactly. *.pdf creates the list, and then for sets the variable $pdf to each element of the list.

I could have called it file or even rose. Just a placeholder.

Glad it's done.

B
 
Exactly. *.pdf creates the list, and then for sets the variable $pdf to each element of the list.

I could have called it file or even rose. Just a placeholder.

Glad it's done.

B

Ok so just to clarify cause I'm slow. When do you use the $ sign and when not ? In the for statement there is no dollar sign but in the do statement there is. Does $ mean 'one entry of a variable array' ?
 
Use it when you want the value substituted in, not when you are defining it (see POSTPATH vs $POSTPATH too).

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