lanier has asked for the wisdom of the Perl Monks concerning the following question:
//snippet of sorted for File1
acp.lanier.com = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = tcp.lanier.com) (PROTOCOL = TCP) (HOST = st.lanier.com) (PORT = 1533) ) ) (CONNECT_DATA = (SID = utl) ) )
//File 2 unsorted
/want to ignore this part############## # Filename......: # Name..........: # Date..........: ################ /
sdcht.lanier.com = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = tcp.lanier.com) (PROTOCOL = TCP) (Host = sb.lanier.com) (Port = 1521) ) ) (CONNECT_DATA = (SID = sdcht) /want to ignorthis(GLOBAL_NAME = sdcht.lanier.com)/ ) )
I obtain the general pattern and input into an array. sort the unsorted array. and the compare the files and print what is different. If anyone can tell me where I am going wrong in my logic or coding.#! /u/ss/bin/perl -w $pattern = qr/ ([^=]*=\s*\(DESCRIPTION\s*=\s* \(ADDRESS_LISTS\s*=\s*\(ADDRESS\s*=\s* \(COMMUNITY\s*=\s*[^)]*\)\s*\(PROTOCOL\s*=\s*TCP\)\s* \(HOSTS\s*=\s*[^)]*\)\s*\(PORTS\s*=\s*\d+\)\s*\)\s*\)\s* \(CONNECT_DATA\s*=\s*\(SID\s*=\s*[^)]*\)\s* [(GLOBAL_NAME\s*=\s*[^)]*)]?\s* \)\s*\)/x; open (FILE, "tnsnames.ora") or die $!; while (<>) { if(/$pattern/){ push @unsorted, $pattern; } } close FILE; @unsorted = sort @unsorted; open (FILE, "tns.log") or die $!; while (<>) { if(/$pattern/) { push @sorted, $pattern; } } close FILE; $x = pop @unsorted ||'' ; $y = pop @sorted ||'' ; while ($x || $y) { if($x gt $y) { print "missing from file1: $x \n"; $x = pop @sorted ||'' ; } elsif ($y gt $x) { print "missing from file2: $y \n"; $y = pop @sections ||'' ; } else{ $x = pop @sorted ||'' ; $y = pop @sections ||'' ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort and Compare Files
by tilly (Archbishop) on May 14, 2003 at 17:48 UTC | |
|
Re: Sort and Compare Files
by Thelonius (Priest) on May 14, 2003 at 19:08 UTC | |
|
Re: Sort and Compare Files
by lanier (Initiate) on May 19, 2003 at 15:42 UTC |