Finding missing files that are named sequentially with Perl?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding missing files that are named sequentially with Perl?
# 1  
Old 09-18-2009
Finding missing files that are named sequentially with Perl?


I am new to Perl, in fact I am on chapter one of the book. Smilie However I am in need of a Perl Script faster than I can finish the book. Perhaps someone can help me with my immediate need while I read my book.

I have a directory with hundreds of files that are all named like ABCD_21308_0636456392_001.ARC with the 21308 part of this file name being the sequential part of the files. Files come and go from the folder in which they reside with the oldest going first while new ones are created in the folder. The goal is to find missing files in the sequential order as they occure so as to retreive the missing file from the source in a timely fashion.


# 2  
Old 09-18-2009
If those are an Oracle archived redo log files just use the rman delete input clause during the backup. If that's the case, there is no need to reinvent the wheel.

backup archivelog  all delete input

# 3  
Old 09-18-2009
Finding missing files that are named sequentially with Perl?

No they are not Oracle log files. In fact the file extention used here is fictional. Its actually .txt

Last edited by newftronics; 09-18-2009 at 01:35 PM..
# 4  
Old 09-18-2009
Something like this:
perl -le'
    %files = map { ( split "_" )[1] => 1 } glob "*.ARC";
    @seq = sort { $a <=> $b } keys %files;
    print join "\n", grep !$files{$_}, $seq[0] .. $seq[$#seq];

You should adjust the glob for your needs (ARC => txt).

In Perl 5.10 you don't need the hash:

perl -E'
    @seq = sort { $a <=> $b } map { ( split "_" )[1] } glob "*.ARC";
    for ( $seq[0] .. $seq[$#seq] ) {
        say unless $_ ~~ @seq;

P.S. Now that I think ..., I'm taking min and max values from the available files.
Is that a correct assumption? What if a file below or above that boundaries is missing?

Last edited by radoulov; 09-18-2009 at 05:40 PM..
# 5  
Old 09-18-2009
Finding missing files that are named sequentially with Perl?

Thank you radoulov ... your code was exactly what I needed. SmilieSmilie This will make life easier while I learn Perl.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding Files with Perl on a Hidden Dir?

Greetings! Been a while since I futzed around with Perl, and came upon a minor headscratcher for the community ;) Here's the basic code which I'm trying to make tick over:#!/usr/bin/perl use strict; use warnings; use diagnostics; print " starting "; while (-e "~/.somedir/testFile")... (9 Replies)
Discussion started by: LinQ
9 Replies

2. Shell Programming and Scripting

Sequentially rename multiple files

Hello team, We wish to develop a script as follows : 1. Rename multiple files in the following way: example Original file names : test.txt and dummy.txt New file names : test.$(date +"%F").AAAAA<serialno_1>.BBBBBB.p and dummy.$(date +"%F").AAAAA<serialno_2>.BBBBBB.p 2. The... (3 Replies)
Discussion started by: H squared
3 Replies

3. Shell Programming and Scripting

How to introduce the missing number sequentially?

Dear Help, I have an input file which looks like below 002 1000 2000 3000 003 2000 3000 4000 005 1000 2000 6000 I would like to have an output which inserts the missing number in sequential sorting as shown below... 001 0 0 0 002 1000 2000 3000 003 2000 3000 4000 004 0 0 0 005 1000... (5 Replies)
Discussion started by: Indra2011
5 Replies

4. Shell Programming and Scripting

[Solved] awk manipulation of sequentially named files

Hello, I am a very novice user of awk, I have a set of files named file001, file002, file003, file004, etc., each contains four fields (columns of data) separated each by a uneven number of spaces. I want to substitute those spaces by a TAB, so I am using this line of awk script: awk -v OFS="\t"... (4 Replies)
Discussion started by: jaldo0805
4 Replies

5. Shell Programming and Scripting

perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here. I am fairly new to perl. I am trying to rewrite my shell scripts to perl. Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what... (0 Replies)
Discussion started by: brianjb
0 Replies

6. Red Hat

Named.conf file missing Centos 5.

hello everyone, I have install centos 5 recently.The file /etc/named.conf not found. I have installed BIND using yum. so now what to do ?? should i create named.conf file manually ??? please help me. thanks, sharlin. :) (1 Reply)
Discussion started by: sharlin
1 Replies

7. Shell Programming and Scripting

Finding BEGINNING & ENDING positions of sequentially increasing sublists from a perl numeric array

I have got an Perl array like: @array = (1,2,3,4,5,6,1,2,3,4,1,2,1,2,3,4,5,6,7,8,9...............) This numeric sequence will be always sequentially increasing, unless it encounters, The beginning of the new sequentially increasing numeric sequence. SO in this array we get sequentially... (5 Replies)
Discussion started by: teknokid1
5 Replies

8. Shell Programming and Scripting

Finding missing tags

I have a list containing strings. All strings should have either "smp" or "drw" else it is considered an error. I have written this code below. Any better ideas to tackle this? set fdrw = 0 set fsmp = 0 foreach f ($Lst) set fdrwtag = `echo $f | awk '/drw/'` set fsmptag = `echo $f | awk... (1 Reply)
Discussion started by: kristinu
1 Replies

9. Shell Programming and Scripting

Finding perl files without documentation

I have an application consisting of a number of perl files. I want to find those perl files that have no documentation yet, so I tried the following from the root level of the directory where the application resides: perldoc -r * The output is something like the following: No documentation found... (2 Replies)
Discussion started by: figaro
2 Replies

10. UNIX for Advanced & Expert Users

FTP Files Sequentially

Hi Gurus, i have to transfer files one by one from ftp server to target server all files which is to be transferred lies in one ftp folder i have to move those files sequentially from ftp to target and must verify files for successful transmission . then i have to delete corresponding... (1 Reply)
Discussion started by: harim
1 Replies
Login or Register to Ask a Question