Preserving whitespace in a for loop

I obviously haven't learned my lesson with shell and whitespace.

find /path/to/some/where/ -name  "*.pdf"  | awk '{print $5}'| uniq -d

results:

some Corporation
other Corporate junk
firmx


 

Works fine from cmdline but the whitespace turns into another FS in a for loop.

for i in ` find /path/to/some/where -name  "*.pdf"  | awk -F/ '{print $5}'| uniq -d`;do echo $i; done

returns:

some 
Corporation
other 
Corporate 
junk
firmx

I tried using OFS and ORS to no avail.

Better use a while/read construct; this will preserve the blanks.

find /path/to/some/where/ -name  "*.pdf"  | awk '{print $5}'| uniq -d |while read name ; do
     echo $name
done

Can't see how you got two fields from your awk '{print $5} .
Please post some sample output from the following find statement (note the single quotes instead of double quotes):

find /path/to/some/where/ -name  '*.pdf' -print

Awesome, didn't realize you could load a while loop like that.

methyl

The output is identical with single quote as it is with double quotes.

In many circumstances the output will be identical.
I was more interested in what the output looked like.
Your first example does not have a "-F /" delimiter flag to awk. I cannot see how the command as posted could produce the output as posted.

The missing -F/ is a pasting failure on my part. The original command contained it.

I guess you are looking for unique subdirectory names at the 4th level where a subdirectory contains files of name *.pdf. Combining the various ideas above and refining the final display to preserve spaces we get:

#!/bin/ksh
find /path/to/some/where/ -type f -name '*.pdf' -print | \
        awk -F/ '{print $5}'| sort | uniq -d | while read name
        do
                echo "${name}"
        done