sequential : how to find the missing numbers within a sequence of files that have sequential numbers attached to them?
Counting how many files one has is a simple matter, but when I got a few hundred and some are missing within the total sequence what is a quick way to find out which ones are missing within the sequence of the total and put them in a file listing only the numbers that are not presence within the sequence?
say we have here these numbers, whereas it is to be all numbers within that sequence of 1-19. we search though the files with the attached numbers and only see these numbers. 1, 2 , 3, 5, 7, 8, 19. the means to search this and report back would result in this means saying that, 4, 6, 9-18 are missing and spelling out the last sequence in numbered order as well. The whole sequence of missing numbers being printed out or into a file. the actual pattern being. Code:
FileName-xxx-xxxxxxx.ext the middle three x's being the ones to look at to find the missing numbers within the entire sequence of numbers. |
Not tested but you could try something like:
Code:
testfor.sh Code:
./testfor.sh /path/to/folder/FileName- -*.ext |
Ok I got a script to get the numbers to use in a input file - removed the leading zeros, but the output is out of sequence.
Code:
#!/bin/bash Quote:
|
Ok this is defiantly not working yets.
the sequence is 1 - 270 Code:
#!/bin/bash Code:
userx%slackwhere ⚡ production ⚡> ./getNumberOffFiles Code:
awk '$1!=p+1{print p+1"-"$1-1}{p=$1}' Numbers Code:
162-162 I know there are more missing than that. 164 - 170 for starters. maybe I got that awk backwards or something I snagged it off the net. it is not incrementing to the next valid number and printing out the missing ones between the first missing one and the next valid number. |
Quote:
I might have to play with it to get just the numbers off the file? I'll give it a go just to see what that does. |
well I got it to a point - and maybe this is too much for all of
Code:
Code:
Missing: 162 awk awk '$1!=p+1{print p+1"-"$1-1}{p=$1}' Numbers Code:
162-162 |
Do you want a Perl version?
|
Quote:
if range is between 1 - 100 and missing is 4 - 10, 44, 85 then it prints 4 5 6 7 8 9 10 44 85 NOT 4-10 and whatever else gets printed. |
Quote:
Code:
sort -n Numbers Edit: Oh...you already got that... I can almost see the perl in my minds eye. Be interested to see what Laserbeak comes up with. |
Quote:
yeah lets just see if he is up for the challenge MUHahahahaha :D |
I couldn't resist. Am interested in Laserbeak's comments and/or version.
Hopefully comments are self-explanatory. Code:
#!/usr/bin/perl or /path/to/thisscript.pl maxvalue to see on STDOUT |
what i would do is create a file containing the integers in the order you want.
create another file with the filenames. and then diff the two files. |
Quote:
Code:
userx%slackwhere ⚡ production ⚡> diff Numbers FILES |
Quote:
Code:
userx%slackwhere ⚡ scripts ⚡> ./perl-find-missing-numbers maxvalue chnged it - same output then checked to be sure I got perl .. Code:
userx%slackwhere ⚡ scripts ⚡> perl -version |
you need the output of
Code:
which perl on my server: Code:
$ which perl Oh. You get nothing if you don't supply a max value on the command line -- there should probably be a test for that: Code:
./perl-find-missing-numbers.pl 270 (your #! must be right, or you'd have got errors) |
All times are GMT -5. The time now is 12:03 PM. |