[SOLVED] for loop to process files

I need to process a dirtree containing ms office files such that each file is stored as a variable and also, just the file file stem. Why? They will be using as input and output parameters for another script. For example /path/to/second_script -i filename.docx -o filename

Here's what I have so far. The problem is that the output of the find command is treated as a single word.

#!/bin/bash
for i in "$(find . -type f \( -iname "*.doc" -o -iname "*.docx" \))" ; do
  out="${i%.*}"
  echo "$i"
  echo "$out"
# /bin/process -i "$i" -o "$out"
done

And here is the output:

./getit.docx
./get it.doc
./getit.doc
./getit.docx
./get it.doc
./getit

What's the trick to make this work?

EDIT: here is the working code; maybe other newbs will learn something :slight_smile:

while IFS= read -r -d '' file
do
  echo "$file" "${file%.*}"
done< <(find -regex '.*\.\(ppt\|pptx\|xls\|xlsx\|doc\|docx\)' -print0)

Less is more, and with less latency, on the pipe:

find . -type f | grep -E '\.(ppt|xls|doc)(x$|$)' | while read i
do
  out="${i%.*}"
  echo "$i $out"
done
 
or let sed do heavy lifting:
 
find . -type f | sed '
 s/\(.*\)\.pptx\{0,1\}$/& \1/
 t
 s/\(.*\)\.xlsx\{0,1\}$/& \1/
 t
 s/\(.*\)\.docx\{0,1\}$/& \1/
 t
 d
 '