Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

one-line split file sequence checker

by wdef2 (Acolyte)
on Jan 21, 2008 at 23:27 UTC ( #663473=snippet: print w/replies, xml ) Need Help??
Description: Identify missing parts in a sequence of split files in the current dir eg file.1, file.03, file.005 etc => prints 2 and 4 I'm sure this could be made tighter, I'm still a Perl newbie.
perl -e 'for $c (sort {$a<=>$b} grep(s/^.+?([0-9]+)$/$1/, `ls *[0-9]`)){ ++$n == $c || print grep(s/$/\n/, $n...$c-1) ; $n=$c }'
Replies are listed 'Best First'.
Re: one-line split file sequence checker
by jwkrahn (Monsignor) on Jan 22, 2008 at 21:09 UTC
    "tighter" sure, change  grep(s/^.+?([0-9]+)$/$1/, to  map(/.([0-9]+)$/, and change  `ls *[0-9]` to  <*[0-9]> and change  grep(s/$/\n/, to  map("$_\n", .

      You can make map(/.([0-9]+)$/, into map(/.(\d+)$/, too.

        perl -e 'for $c (sort {$a<=>$b} map(/.(\d+)$/, <*[0-9]>)){ ++$n == $c || print map("$_\n", $n...$c-1) ; $n=$c }'

        Ah, that's getting closer to the line noise effect I was looking for, thanks ;=) Time to read up on that map command and why <> is globbing filenames in the current dir. I'm almost pleased to see there's no offered improvement to the basic idea. There's no way to get rid of that 'for' iterator, or the 'print'? -lane ? Any shorthand for sort {$a<=>$b}? Just wondering.
Re: one-line split file sequence checker
by poolpi (Hermit) on Jan 24, 2008 at 13:28 UTC
    With files :
    file.1 file.02 file.003 file.5 file.00007 file.011
    perl -e '/\.0*(\d+)$/and$t[$1]=1for<*>;map{$t[$c]?1:print"$c ";$c++}@t'
    Output :
    4 6 8 9 10



    'Ebry haffa hoe hab im tik a bush'.  Jamaican proverb
      Nice, thx. Could golf slightly further I suppose to:

      perl -e '/(\d+)$/and$t[$1]=1for<*>;while($c<$#t){$t[++$c]||print "$c "}'

      I like that since it seems quite readable as well (at least for me) Though is map more efficient than while?

        map may or may not be more efficient, but it's certainly shorter:

        perl -le '/(\d+)$/and$t[$1]=1for<*>;map$t[$_]||print,1..$#t'
Re: one-line split file sequence checker
by ambrus (Abbot) on Jan 25, 2008 at 09:26 UTC
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://663473]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2016-10-25 13:04 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (319 votes). Check out past polls.