On Thu, May 17, 2001 at 12:19:51AM +1000, Paul Robinson wrote:
> Got a problem writing a shell script in sh. What it's supposed to
> do is look at a base path, get a directory listing and for each directory
> there it needs to concat the base path with the dir name and run a cat *
> |grep "sometext" on each.
I'm not sure if I understand the problem and I don't know what else you
have available, but doesn't
find . -type f -print | xargs grep "sometext"
do what you want (and you can omit the '.' and -print for GNU find)?
> I can get a directory listing by doing a ls -l |cut -b 47-57
This looks full of "magic numbers", but I assume it works for you. On my
Linux box, this gives
16 22:13 i
16 22:14 l
16 22:13 l
16 22:13 l
16 22:13 m
16 22:13 m
16 22:13 m
etc
which is possibly because my username and group are longer than yours.
But still, if portability is important this could be significant.
> and that gives a list of directories but I cannot get either the path
> concatination working or the "do for each" bit working.
Is this what you mean?
for i in `ls -l |cut -b 47-57`
do
directory=$basepath$i
cat $directory/* | grep "sometext"
done
Maybe helpful, maybe not.
Cheers,
Malcolm
--
I don't have a solution, but I admire your problem.
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug