[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Finding files not present (challenge to your intelligence)



Hi,

thank you very much for your solution; it is very sharp. I was doing
things the hard way. I like the shell solution very much.

Regards,

Eloy.-

> On Mar 26, Eloy A. Paris wrote
> : Hi,
> : 
> : I was given a text file containing one file name (no full path name)
> : per line. My task consists of searching the entire filesystem and
> : generate a list of the files that are NOT present.
> 
> 1. The perl solution:
> -------------------------------
> #!/usr/bin/perl
> # * probably overkill, if your file list
> #   is rather short.
> # * probably storing the existing files in a @Array
> #   and grepping is faster
> # * probably a shell line with sort / uniq / comm would
> #   do the same job
> 
> # generate a list of existing files
> open(IN, "find . -type f -printf \"%f\n\"|") or die;
> while(<IN>) { chomp; $Files{$_} = 1; }
> 
> # read in the search list and see, the file exists
> open(IN, "searchlist") or die;
> while (<IN>) { chomp; $Files{$_} or print "Missing: $_\n"; }
> 
> 
> 2. The Shell solution
> --------------------------------
> 
> 	find -type f -printf "%f\n" | sort > files.exist
> 	sort < searchlist > files.search
> 	comm -1 -3 files.exist files.search
> 
> 	Heiko Schlittermann
> ---------------------------------------------
> Heiko Schlittermann / Internet & Unix-Support
> Kamenzer Str. 52              D-01099 Dresden 
> Voice: +49-172-7909055     Mail: heiko@sax.de
> 

-- 

Eloy A. Paris
Information Technology Department
Rockwell Automation de Venezuela
Telephone: +58-2-9432311 Fax: +58-2-9430323


Reply to: