script formatting question?

Robert Meyer meyer_rm at yahoo.com
Mon Apr 22 15:30:32 EDT 2002


This is obscure, but have you tried using the '-Q' flag to the 'ls' command. 
Puts quotes around the whole file name so 'ls -lQ' gives:
-rw-r--r--    1 rmeyer   rmeyer        273 Apr 22 14:03 "file with spaces"

I would guess that then next thing to say is: "the implementation is an
exercise left for the reader." :-)

Of course, there's really UGLY stuff you can do with awk:
awk '{printf "%10s%15d %s %s %s %s\n", $3, $5, $9,  $10, $11, $12};'
run on the output of 'ls -l' but the tacit assumption would be no more than one
space in a row in the file name and no more than 4 words to the file name
(season to taste).

Of course, you could use the perl 'opendir' and 'readdir' routines and rewrite
'find' but... ummm... never mind...

I tried doing something with 'cut' but you can't be sure where the string for
the file name starts since 'ls' will push the thing to the right if the size is
greater than 99,999,999 bytes in size...

This one's ugly, no matter how you look at it.  You could really get messy
quick trying to take into account any insanity that 'ls' can come up with.  The
only rational way to do this that I can think of is to get hold of a
programming language (your choice: C, C++ Perl, Java) and recursively traverse
the directory tree with 'opendir/readdir', grabbing the data structures and
printing what you want after appropriate pattern matching...  EWWW!!!  If you
are going to do this a lot, makes sense.  If not...

Hope I've given you some grist for the mill...

Cheers!

Bob

--- Darin Perusich <Darin.Perusich at cognigencorp.com> wrote:
> hello,
> 
> i'm beating myself up trying to figure this out and i need some outside 
> input.
> 
> i'm trying to do a recursive search of a filesystem for all documents 
> with a certain extension, *.doc, *.xls ./etc. when i get this list i 
> need the following inforamtion about those files:
> 
>  name  size(in bytes)  /path/to/file
>  ----  -------------   -------------
>  darin 64000   myresume.doc
> 
> i accomplish by:
> 
> find /home/darin -name "*.doc" -exec ls -l {} \;  \
> |awk '{print $3 FS $4 FS $8}'
> 
> the problem i'm running into is files with spaces in the name, i.e my 
> resume 2000.doc. since awk uses space and tab as the field seperator you 
> don't get the full path of the file just up to the space.
> 
> i'm sure that there's an easy way to accomplish this in perl, but since 
> i don't know much, next to nothing about perl i'm stuck.
> 
> any ideas?
> 
> for those that are interested i'm writing a script that bulk loads 
> binary files into a mysql driven document management systems, sdms 
> (simple document mangement system).
> 
> -- 
> Darin Perusich
> Unix Systems Administrator
> Cognigen Corp.
> darinper at cognigencorp.com
> 

=====
Bob Meyer
Knightwing Communications, Inc.
36 Cayuga Blvd
Depew, NY 14043
Phone: 716-308-8931 or 716-681-0076
Meyer_RM at Yahoo.com

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/


More information about the nflug mailing list