RE: [newbie] [Somewhat OT] Recursing in bash

2004-05-15 Thread Bill Shirley
Sounds like a job for 'find' !

find /home/bill -type f -name '*.doc' -exec somecommand someargs {} \;
 ^  ^   ^  ^  ^   ^ ^
 where to   only look name  what cmdcommand   | +-- mandatory
   startat files pattern to run  args |
  |
   will insert found name here

you can harmlessly try it:

find /home/bill -type f -name '*.doc' -exec ls -s {} \;

or

find /home/bill -type d -exec ls -ld {} \;


'man find' is your friend.


HTH,
Bill


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf Of robin
 Sent: Friday, May 14, 2004 4:19 PM
 To: [EMAIL PROTECTED]
 Subject: [newbie] [Somewhat OT] Recursing in bash


 I'm trying to write a bash script that will recurse through a
 directory,
 find Word files, then run antiword on them. Unfortunately,
 I'm stuck on
 the first stage, which is to get it to recognise a directory. I'd
 thought this would work

 for i in *
do
  if [-d $i]; then
cd $i

 and so on, but the third line obviously has the wrong syntax,
 as I get
 [!: command not found. Any ideas?

 Sir Robin

 --
 Doubt is not a pleasant condition, but certainty is absurd.
 - Voltaire

 Robin Turner
 IDMYO
 Bilkent Universitesi
 Ankara 06533
 Turkey

 www.bilkent.edu.tr/~robin






Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com
Join the Club : http://www.mandrakeclub.com



Re: [newbie] [Somewhat OT] Recursing in bash

2004-05-14 Thread Todd Slater
On Fri, May 14, 2004 at 11:18:32PM +0300, robin wrote:
 I'm trying to write a bash script that will recurse through a directory, 
 find Word files, then run antiword on them. Unfortunately, I'm stuck on 
 the first stage, which is to get it to recognise a directory. I'd 
 thought this would work
 
 for i in *
   do
 if [-d $i]; then
   cd $i
   
 and so on, but the third line obviously has the wrong syntax, as I get 
 [!: command not found. Any ideas?

find can be your friend. You can find directories and files, and specify
recursion depth using -mindepth and -maxdepth. So an easy solution
(depending on what you want to do with what you find) could be something
like

find /home/robin/crappywordfiles -type f -iname '*.doc'

by default it will recurse crappywordfiles to infinity finding all files
that end in .doc, .DOC, .dOC etc. 

or if you really wanna cd to the directories themselves, something like

for i in `find /home/robin/crappywordfiles -type d`
do
cd $i
rm -f *.doc
done

hth,
Todd


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com
Join the Club : http://www.mandrakeclub.com



Re: [newbie] [Somewhat OT] Recursing in bash

2004-05-14 Thread robin
Todd Slater wrote:
On Fri, May 14, 2004 at 11:18:32PM +0300, robin wrote:

I'm trying to write a bash script that will recurse through a directory, 
find Word files, then run antiword on them. Unfortunately, I'm stuck on 
the first stage, which is to get it to recognise a directory. I'd 
thought this would work

for i in *
 do
   if [-d $i]; then
 cd $i
		
and so on, but the third line obviously has the wrong syntax, as I get 
[!: command not found. Any ideas?


find can be your friend. You can find directories and files, and specify
recursion depth using -mindepth and -maxdepth. So an easy solution
(depending on what you want to do with what you find) could be something
like
find /home/robin/crappywordfiles -type f -iname '*.doc'

by default it will recurse crappywordfiles to infinity finding all files
that end in .doc, .DOC, .dOC etc. 

or if you really wanna cd to the directories themselves, something like

for i in `find /home/robin/crappywordfiles -type d`
do
cd $i
rm -f *.doc
done
Works a treat!

The reason I'm messing around with evil Word files is that it is the 
format I usually receive essays in (I've tried teaching my students the 
save as function in Word, but it doesn't sink in, and besides, other 
formats that Word can produce are equally problematic). It's not 
normally a problem, since I can open them in OpenOffice, write my 
comments and post them back, but sometimes I also want to do some 
analysis on them, for which plain text is essential (see 
http://lists.bilkent.edu.tr/~robin/cgibin/concord.cgi for something I 
did a few years back).

Thanks a lot,

Sir Robin

--
Doubt is not a pleasant condition, but certainty is absurd.
- Voltaire
Robin Turner
IDMYO
Bilkent Universitesi
Ankara 06533
Turkey
www.bilkent.edu.tr/~robin



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com
Join the Club : http://www.mandrakeclub.com