The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-26-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Create a list of all files which should be there, and compare.

Code:
perl -le 'for my $i (1..50) { print "missing: statistics.$i" unless -f "statistics.$i" }'
I meant for the Perl script to just generate the list, but it turned out to be so easy to do it all in Perl. Sorry, folks (-:

Just to illustrate my original proposal, here's another approach, using just simple shell commands:

Code:
yes . | head -50 | nl | sed -e 's/^ *\([1-9][0-9]*\) .*/statistics.\1/' >list
ls -rt statistics.* | diff list -
The file "list" is generated with the nl utility to have line numbers, and the file name prefix is added using sed. (This came out pretty tortured -- it would arguably be a lot easier with awk, but let's just say that using scripting languages would be cheating, okay?) Then we compare that list against the actual directory listing. This requires that your diff accepts "-" to mean "read the other file from standard input;" otherwise, you'll need to use two temporary files. (Don't forget to remove them when you're done.)

Last edited by era; 04-26-2008 at 01:34 PM.. Reason: Alternate approach, just for illustration