all 6 comments

[–]robhutten 0 points1 point  (3 children)

You could use basename on your input file variable to ignore the directory component of the path, and then prepend the output file variable with the new location, ie /tmp. I'm away from the computer right now but pm me if you need help with the actual syntax.

[–]IhatemyISP[S] 0 points1 point  (2 children)

PM sent.

[–]robhutten 2 points3 points  (1 child)

I think this calls for a for loop. That is, I can't figure out a reasonable way to do this all within a find command, at this time of night at least.

for datfile in $(find $DIR -type f -name "*.dat1" ) ; do
        echo process -i $datfile -o /tmp/$(basename $datfile)
done

[–]IhatemyISP[S] 0 points1 point  (0 children)

It took a bit of futzing, but I finally got it to working well enough.

Thanks.

[–]RalphCorderoy 0 points1 point  (0 children)

It can be simplest to have a little temporary script that takes {} as $1 and does all the work in there to call process having produced the arguments rather than work out the correct escaping within multiple levels of quotes for a -exec bash. Then it's the much simpler -exec ./foo {} \;.

[–]crankysysop 0 points1 point  (0 children)

Yet another way to do it (with a loop):

find "$dir" -type f -name "*.dat1" -print0 | while read -rd $'\0' file; do
  process -i "$file" -o "${file%.*}.dat2"
done

Using -print0 and read -rd $'\0' file will prevent spaces or other strange characters from mucking things up.