Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a big bunch of directories, each with a series of .pdf files. Some of these files have successfully converted to .csv, some have not. An example directory listing using find ./:

./test5.pdf.csv
./test6.pdf
./test1.pdf.csv
./test3.pdf
./test1.pdf
./test3.pdf.csv
./test4.pdf.csv
./test7.pdf
./test2.pdf
./test5.pdf
./test4.pdf
./test2.pdf.csv
./test8.pdf

How would I return a list of files that have not successfully converted?

In other words, what are the files that don't have a .csv.pdf counterpart?

In this example, it would be test{6,7,8}.pdf.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Here's how it works with find:

find . -name "*.pdf" | while read F; do test -f "${F}.csv" || echo "$F"; done

Using find is preferable to shell globbing as it has no limitation on the number of arguments and it works with spaces and special characters.

share|improve this answer
    
Rad, this is totally what I was looking for. Just tested it, works great! –  aendrew Jan 23 at 20:52

I couldn't find a way to do it with find directly, but it's very easy using a for loop:

for file in *.pdf; do [ -f ${file}.csv ] || echo $file; done

If you need to run it at the top directory and have it recurse, you could use find like this:

for file in $(find . -iname '*.pdf'); do [ -f ${file}.csv ] || echo $file; done

which would output something like this:

./dir2/test7.pdf
./dir2/test6.pdf
./dir2/test8.pdf
./dir3/test7.pdf
./dir3/test6.pdf
./dir3/test8.pdf
./dir1/test7.pdf
./dir1/test6.pdf
./dir1/test8.pdf

Careful with that last one though, if you aren't sure there won't be any strange characters in the input filenames, make sure you set IFS environment variable accodingly:

OFS=$IFS
export IFS=$'\n'

Of course, from here on it only gets nastier.

I'm assuming you use bash.

share|improve this answer
    
This is a great, detailed answer if you have a less-than-stellar version of find (I think it's a bit different on Solaris) or don't like find -- I accepted the other answer because it's closer to my initial question, but this one is pretty terrific as well. Wish I could accept both! –  aendrew Jan 24 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.