Missing sequences in filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Missing sequences in filenames
# 8  
Old 10-10-2014
What is your OS and version?

If I do this first:
Code:
$ mkdir missing
$ cd missing
$ touch OOOAAAALOGS00001.txt OOOAAAALOGS00002.txt OOOAAAALOGS00003.txt OOOBBBBLOGS00005.txt OOOBBBBLOGS00006.txt OOOBBBBLOGS00007.txt OOOCCCCLOGS00007.txt OOOCCCCLOGS00008.txt OOOCCCCLOGS00010.txt
$ ls 
OOOAAAALOGS00001.txt	OOOAAAALOGS00003.txt	OOOBBBBLOGS00006.txt	OOOCCCCLOGS00007.txt	OOOCCCCLOGS00010.txt
OOOAAAALOGS00002.txt	OOOBBBBLOGS00005.txt	OOOBBBBLOGS00007.txt	OOOCCCCLOGS00008.txt

aNd when I then run the script I get:
Code:
$ printf "%s\n" *.txt | awk -FLOGS '$1==P[1]{for(i=P[2]+1; i<$2+0; i++) printf "%s%05d\n", $1 FS, i} {split($0,P)}'
OOOCCCCLOGS00009

What do you get?
# 9  
Old 10-10-2014
In bash/ksh:
Code:
unset f1last
while read f
do
  f1=${f%LOG*}
  f2=${f#*LOG}
  f2=${f2%.txt}
  if [ $f1 = "$f1last" ]
  then
    if (( f2 != ( f2last + 1 ) ))
    then
     echo "Gap in $f1 between $f2last and $f2."
    fi
  fi
  f1last=f1
  f2last=f2
done < fn_list

# 10  
Old 10-13-2014
Hi,

thank you a lot for your help!
With the examples i have posted, this is working OK!

But, in fact the files do not have this pattern, OOOAAAALOGS etc...

BUT: OOOABCDELOGSXXXXXX.txt

and im not find a way to make this work on this kind of files.

---------- Post updated at 07:52 AM ---------- Previous update was at 03:31 AM ----------

Please, any help regarding this?
I am not getting the result needed.

Many thanks
# 11  
Old 10-13-2014
Got Perl?

Code:
#!/usr/bin/perl
# find_missing.pl
#
use strict;
use warnings;

sub missing {

    my $group = shift;
    my @inventory = sort { $a <=> $b } @$group;

    my $last_seen = $inventory[0];
    my @missing;

    for my $vector (@inventory) {

        # detect missing numbers in the sequence
        if ( $vector - $last_seen > 1 ) {
	    # keep record of missing numbers so far
            push @missing, ( $last_seen + 1 .. $vector - 1 );
        }
	# move the head point of the search
        $last_seen = $vector;
    }
    return \@missing;
}

my %file_groups;
# index file name root into groups
while ( my $line = <> ) {
	chomp $line;
	# separate root of filename from serial and extention
	my ($group, $serial) = $line =~ /(\S+LOGS)(\d+)\.txt/;
	push @{$file_groups{$group}}, $serial;
}

# identify missing serials, if any, for each group
for my $group (keys %file_groups) {
	my $vacancies = missing($file_groups{$group});
	# found any?
	if (@$vacancies) {
		print "Missing files for group $group:\n";
		foreach (@$vacancies) {
			print "$group$_.txt\n";
		}
	}
}

Code:
cat file.list
OOOAAAALOGS400001.txt
OOOAAAALOGS400002.txt
OOOAAAALOGS400003.txt
OOOBBBBLOGS400001.txt
OOOBBBBLOGS400002.txt
OOOBBBBLOGS400003.txt
OOOCCCCLOGS400001.txt
OOOCCCCLOGS400002.txt
OOOCCCCLOGS400004.txt
OOOABCDELOGS40003.txt
OOOABCDELOGS40005.txt
OOOABCDELOGS40008.txt

Code:
perl find_missing.pl file.list
Missing files for group OOOCCCCLOGS:
OOOCCCCLOGS400003.txt
Missing files for group OOOABCDELOGS:
OOOABCDELOGS40004.txt
OOOABCDELOGS40006.txt
OOOABCDELOGS40007.txt

# 12  
Old 10-14-2014
Quote:
Originally Posted by arrals_vl
Hi,

Thank you for you reply.
I have tested this, but still it doesn't do what i want.

Please, anybody who can help me with this?

Thank you o lot!
It does exactly what you specified. How do you expect sth to work if the sample structure you give us does not fit your reality?

Assuming the NEW file name structure, try this and comment:
Code:
awk '{T=substr($0,4,4); C=substr($0,13,6); if (T != TA) {CA=C;TA=T}; while (CA<=C) print "OOO"T"LOGS"CA++".txt"}' file

Pipe an ls output to the awk (as shown above) if you don't have the names in a file.
# 13  
Old 10-15-2014
Revised & tested ksh:
Code:
unset f1last ; while read f
do
  f1=${f%LOGS*}
  f2=${f#*LOGS}
  f2=${f2%.txt}
  if [ $f1 = "$f1last" ]
  then
    if (( f2 != ( f2last + 1 ) ))
    then
     echo "Gap in $f1 between $f2last and $f2."
    fi
  fi
  f1last=$f1
  f2last=$f2
done <<!
OOOAAAALOGS400001.txt
OOOAAAALOGS400002.txt
OOOAAAALOGS400003.txt
OOOBBBBLOGS400001.txt
OOOBBBBLOGS400002.txt
OOOBBBBLOGS400003.txt
OOOCCCCLOGS400001.txt
OOOCCCCLOGS400002.txt
OOOCCCCLOGS400004.txt
OOOABCDELOGS40003.txt
OOOABCDELOGS40005.txt
OOOABCDELOGS40008.txt
!
Gap in OOOCCCC between 400002 and 400004.
Gap in OOOABCDE between 40003 and 40005.
Gap in OOOABCDE between 40005 and 40008.

# 14  
Old 10-16-2014
Thank you very much for your help.
All the three above solutions worked very well.

Thank you again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

2. Shell Programming and Scripting

Escape Sequences

Hi Gurus, Escape sequences \n, \t, \b, \t, \033(1m are not working. I just practiced these escape sequences. It worked first. Later its not working. Also the command - echo inside the script editor shows as shaded by a color. Before that echo inside the script editor wont show like this.... (4 Replies)
Discussion started by: GaneshAnanth
4 Replies

3. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

4. Shell Programming and Scripting

Adding sequences to alignment

I would like to add the following references at the very beggining of all my files: Thus, the resulting file should look like this: Any help will be very much appreciated (6 Replies)
Discussion started by: Xterra
6 Replies

5. Shell Programming and Scripting

trimming sequences

My file looks like this: But I would like to 'trim' all sequences to the same lenght 32 characters, keeping intact all the identifier (>GHXCZCC01AJ8CJ) Would it be possible to use awk to perform this task? (2 Replies)
Discussion started by: Xterra
2 Replies

6. Programming

Trigraph sequences

Hi, i have read trigraph sequence in The C99 Draft (N869, 18 January, 1999) printf("Eh???/n"); will produce printf("Eh?\n"); what does that mean? i tried that but i am getting the same output i.e Eh???/n. what actually these tri graph characters are? any idea why ,when and... (1 Reply)
Discussion started by: MrUser
1 Replies

7. UNIX for Advanced & Expert Users

Deal with binary sequences

Hello, I have come across the necessity for me to deal with binary sequences and I had a few questions. 1- Does any UNIX scripting language provide any tool or command for converting text data to binary sequences? Example of binary sequence: "0x97 0x93 0x85 0x40 0xd5 0xd6 0xd7" 2- If I want... (2 Replies)
Discussion started by: Indalecio
2 Replies

8. Shell Programming and Scripting

copying image sequences

Hi I am running mac osx, I am trying to use the terminal to copy groups of files I have and images sequence that is say 5000 frames long. What I want to do is copy sections of this files sequence to individual shot folder. eg copy say BG_0654 to BG_0765 to shot one folder, and say... (1 Reply)
Discussion started by: jonson
1 Replies

9. Solaris

Available escape sequences

:) Hi, Can any one help me to find available escape sequences in UNIX shell programming? ( Like \n, \c etc,. in C or C++) Iam generating one report using one of the script, in that it is very much essential. Regards, LOVE (6 Replies)
Discussion started by: Love
6 Replies

10. Shell Programming and Scripting

AWK and hex sequences

for file in `seq 1 256`; do printf "\x$file -- $file" ; done ; printf "\n" produces the wrong output. I want to show the ascii codes but need to output a hexidecimal number sequence. I know I should use awk to do this but i'm not sure how cause I forget. what is the awk equivelant of seq... (5 Replies)
Discussion started by: JoeTheGuy
5 Replies
Login or Register to Ask a Question