[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: running a command on many files in many subdirectories



Levi Waldron wrote:
I'm sure this is simple, but maybe someone here can help me do it in a few minutes instead of hours. I have a bunch of files in a bunch of directories, and I want to run the same command on each of them. For each input file, the output file should have the same name except ending in .txt, and the output files should be put a common directory. ie,

java ImageInfo dir1/pic1.jpg > commondir/pic1.txt

etc, repeated over a bunch or directories and jpg files. The subdirectories only go one deep. If this is difficult I could copy all the jpg files into a single directory first with only a little bit of tedium.

Thank you, Levi



for i in `find . -name "*.jpg"`; do java ImageInfo "$i" > `echo $i | sed -e 's~^.*/~commondir/~' -e 's/jpg$/txt/'`; done

all on one line. You probably want to look over <http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html> and/or <http://www.tldp.org/LDP/abs/html/> for guides on how to write simple scripts.




Reply to: