About
Community
Bad Ideas
Drugs
Ego
Erotica
Fringe
Society
Technology
register | bbs | search | rss | faq | about
meet up | add to del.icio.us | digg it
Go Back   Community > Technology > Everything *NIX
Register FAQ Members List Calendar Today's Posts

Everything *NIX This is a general forum about all forms of *nix. Post your ideas and thoughts on this wonderful OS family. Talk about your personal favorite flavor of *nix and why you think it's so much better than the others. Anything pertaining to *nix and *nix administration should be posted here.

Reply
 
Thread Tools Display Modes
  #1   Add RAOVQ to your ignore list  
Old 2008-09-09, 14:22
RAOVQ RAOVQ is offline
Regular
 
the happy land of australia
Default bash assistance, aisle 4

For work, im running a whole bunch of calculations that spit out big output files. I am happy to grep and parse the data i need from them, but depending on how enthusiastic i get, there can be dozens of different directories holding these files. This usually means i need to run a command in every directory, which gets really old quickly.

Ive tried playing with for loops, but to no avail. Does anyone have any hints on how i would make a loop that runs a command in every sub directory (no need for recursive magic or anything, just what a simple "ls -d */" outputs).

Thanks for any help.
Reply With Quote
  #2   Add RAOVQ to your ignore list  
Old 2008-09-09, 14:40
RAOVQ RAOVQ is offline
Regular
 
the happy land of australia
Default Re: bash assistance, aisle 4

i came up with something like this:

#!/bin/bash

FILES=$(ls -d */)
for file in $FILES
do
grep whatever $file/*.out >> ~/file
done

that works assuming i have no spaces in directory names, which i don't do anyway (too annoying to type in).
Comments?
Reply With Quote
  #3   Add Kamisama to your ignore list  
Old 2008-09-10, 04:46
Kamisama Kamisama is offline
Regular
 
Member since 2004
Thumbs up Re: bash assistance, aisle 4

Yeah, something like that was the first thing to come to mind.
Reply With Quote
  #4   Add Prometheum to your ignore list  
Old 2008-09-10, 21:38
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: bash assistance, aisle 4

Yeah, you could also do for i in `ls -d`, but yours works too.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

 
To the best of our knowledge, the text on this page may be freely reproduced and distributed.
 

totse.com certificate signatures
 
 
About | Community | Bad Ideas | Drugs | Ego | Erotica | Fringe | Society | Technology
Hot Topics