![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hpux vg accessible but device files missing! | mariusp | Filesystems, Disks and Memory | 1 | 02-10-2007 03:18 PM |
| checking missing files in side a folder | Nayanajith | UNIX for Dummies Questions & Answers | 4 | 06-26-2006 06:05 AM |
| Missing init files for zsh and bash | maag | SUN Solaris | 2 | 05-04-2006 04:37 PM |
| Missing Library Files | jays337 | UNIX for Dummies Questions & Answers | 5 | 08-18-2005 08:23 PM |
| files missing | cubicle^dweller | UNIX for Dummies Questions & Answers | 4 | 09-22-2003 03:10 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
how to check missing files?
I have 50 files in this directory (/home/unixnewbie/wklyfiles) namely:
statistics.1 statistics.2 statistics.3 statistics.4 statistics.5 statistics.6 statistics.7 statistics.8 statistics.9 statistics.10 .... statistics.20 .... statistics.50 How can i determine if ever there will be some files missing in there? And how to know which exact files are those? Like for example, the statistics.5, statistics.9, statistics.20 and statistics.35 files are missing that week. Thanks in advance. |
|
||||
|
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" }'
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 - Last edited by era; 04-26-2008 at 12:34 PM.. Reason: Alternate approach, just for illustration |
|
||||
|
Wow great, thanks a lot era!
![]() Hope you don't mind a follow-up question, what if i want to store in a file all those existing statistics files? And just just put spaces on those missing files? ![]() Example ==> statistics.1;statistics.2;statistics.3;statistics.4;<space>;statistics.6;......statistics.19; <space>;statistics.21;......statistics.34;<space>;....statistics.50 Hmmm.. |
|
||||
|
Code:
perl -e 'for my $i (1..50) { my $f = "statistics.$i"; print ($i > 1 ? ";" : ""), (-f "$f" ? "$f" : " ") }
print "\n"'
|
|
||||
|
Another bash solution:
Code:
#!/bin/bash
for nbr in $(seq 50); do
if [ ! -e "statistics.$nbr" ]; then echo "statistics.$nbr is missing"; fi
done
Code:
for nbr in $(seq 50); do if [ ! -e "statistics.$nbr" ]; then echo "statistics.$nbr is missing"; fi; done |
|
||||
|
Proper fanatics would perhaps prefer
Code:
for n in $(seq 50); do [ -e statistics.$n ] || echo statistics.$n is missing; done |
|
||||
|
Unfortunately, the seq doesnt work
![]() seq: command not found Any other unix scripting lines possible? Btw, i'm using ksh. Thanks! |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|