Andrew Louie Freedom isn’t Free, it costs folks like you and me

December 28, 2007

Bash, do 1 thing to many different things

Filed under: — andrew @ 11:00 am

It took me forever to figure out batch process many files in different directories, but finally i figured it out! and it’s really simple:So, I have many input files that I want to simulate in different directories. the directories are labeled like so:EF01EF02EF03...and the simulation input files are labeled like:AT-EF01.inpAT-EF02.inpAT-EF03.inp...in their respective directories of course.It’s way too tedious to have to cd into each dir and run the simulation program on the input file, then cd to the next dir and repeat. and bash should be able to do that for me.so in one command:$for f in EF*; do if [ -d $f ]; then cd $f; ses41 AT-$f.inp; cd ..; fi donein english:dear BASH;I would like a list of all names in my current directory that contain the letters EF together. Then I would like you to discard all names that are not directories. for all the names that are directories, I would like you to change the working directory to that name. then I would like you to run the program “ses41” on a file in the directory that looks like the name that you did not discard, but with “AT-” in front and “.inp” at the end. after that operation is complete, change back to the original directory, get the next name, and repeat.thanks, Andrew

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress