Find and rename

Hi,

I was wondering if there is a way to find a particular file and then give it as an input to a program and then dump it into another file.

Something like this:

find ./ -name '*.txt' -exec ~/processText {} > mod.<current_file> \;

I've been trying all sorts of weird things but not getting any good result. Could someone please help me out?

You cannot do redirection inside the -exec.

You could externalize the redirect. Save this as $HOME/procmod:

#!/bin/sh
exec $HOME/processText "$1" >mod."$1"

and then run

find . -name '*.txt' -exec $HOME/procmod {} \;

A more elegant solution would be to avoid the temporary script. You can actually specify it in-line if you spawn a shell and run the redirect using that shell:

find . -name '*.txt' -exec sh -c "$HOME/processText {} >mod.{}" \;

Thank You so much... That helped! :slight_smile: