02-26-2008
Find duplicate value and create an
I have compiled the following works fine, but I am getting IP and device all together. I need to separate them, I need only the duplicate device name and then next paragraph duplicate IP only:
#!/opt/sa/bin/perl
use strict;
use warnings;
use MIME::Lite;
my (%ip, %host, $duplicates);
my $host_file = '/etc/hosts';
open my $file, '<', $host_file or die "can't open $host_file $!";
while (<$file>) {
if( my ($ip, $host) = /^#?([\d.]+)\s+(\S+)/ ) {
if ( defined $ip{$ip} or defined $ip{$host} ) {
$duplicates .= $_;
}
else {
$ip{$ip}++;
$ip{$host}++;
}
}
}
close $file;
my $email_msg = <<EMAIL_MSG;
The following entries in the host file are dulpicates
either by IP address or by hostname.
$duplicates
EMAIL_MSG
my $email = MIME::Lite->new(
From => 'xx@xx.com',
To => 'xv@xv.com',
Cc => '33@xx.com,42@xx.com',
Subject => 'Host file duplicates',
Data => $email_msg
);
$email->send;
Out put of above script:
119.76.169.15 aaaa
129.76.169.2 bcd
#192.16.5.30 headm
#79.158.221.4 tailm
I need output like follwoing when conditions are true:
Duplcate IP found:
139.76.169.15
129.76.169.2
Duplicate host/device found
headm
tailm
Last edited by ricky007; 03-03-2008 at 11:10 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hello all
I like to make search on files , and the result need to be the files that are duplicated? (8 Replies)
Discussion started by: umen
8 Replies
2. Shell Programming and Scripting
I need a perl script which will create an output file after comparing two diff file in a directory path:
/export/home/abc/file1
/export/home/abc/file2
File Format: <IP>TAB<DeviceName><TAB>DESCRIPTIONS
file1:
10.1.2.1.3<tab>abc123def<tab>xyz.mm1.ppp.... (2 Replies)
Discussion started by: ricky007
2 Replies
3. Shell Programming and Scripting
Hi all:
Let's suppose I have a file like this (but with many more records).
XX ME 342 8688 2006 7 6 3c 60.029 -38.568 2901 0001 74 4 7603 8
969.8 958.4 3.6320 34.8630
985.5 973.9 3.6130 34.8600
998.7 986.9 3.6070 34.8610
1003.6 991.7 ... (4 Replies)
Discussion started by: rleal
4 Replies
4. Shell Programming and Scripting
I have a directory with images:
-rw-r--r-- 1 root root 26216 Mar 19 21:00 020109.210001.jpg
-rw-r--r-- 1 root root 21760 Mar 19 21:15 020109.211502.jpg
-rw-r--r-- 1 root root 23144 Mar 19 21:30 020109.213002.jpg
-rw-r--r-- 1 root root 31350 Mar 20 00:45 020109.004501.jpg
-rw-r--r-- 1 root... (2 Replies)
Discussion started by: Ikon
2 Replies
5. Shell Programming and Scripting
What utility do you recommend for simply finding all duplicate files among all files? (4 Replies)
Discussion started by: kiasas
4 Replies
6. Shell Programming and Scripting
Hi all,
I need to create duplicate directories and sub directories (only the directories not the files or file contents) with the same permissions. Can some one guide me in doing this. I could able to create but here the permissions should be the same how can i do this in linux.
Thanks in... (5 Replies)
Discussion started by: Olivia
5 Replies
7. Shell Programming and Scripting
Hi,
In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'.
In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies
8. Shell Programming and Scripting
I have a file contails as below
I/P:
123456
123456
234567
987654
678905
678905
Like above i have 1000's of entries
I need output as below
O/P:
123456
678905
I'm using uniq -d filename it is showing results but it is missing few duplicate entries and i dont know why.Please... (9 Replies)
Discussion started by: buzzme
9 Replies
9. Shell Programming and Scripting
Hi All ! I am trying to copy all files with extension .sh to one folder, following command I am using
find . -name \*.sh -print0 | xargs -I{} -0 cp -v {} Scripts/
above command working fine but I have some .sh file with same base name different directory, so I would copy all .sh file including... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies
10. Shell Programming and Scripting
Dear folks
I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies
DUP(2) System Calls Manual DUP(2)
NAME
dup, dup2 - duplicate a descriptor
SYNOPSIS
newd = dup(oldd)
int newd, oldd;
dup2(oldd, newd)
int oldd, newd;
DESCRIPTION
Dup duplicates an existing object descriptor. The argument oldd is a small non-negative integer index in the per-process descriptor table.
The value must be less than the size of the table, which is returned by getdtablesize(2). The new descriptor returned by the call, newd,
is the lowest numbered descriptor that is not currently in use by the process.
The object referenced by the descriptor does not distinguish between references using oldd and newd in any way. Thus if newd and oldd are
duplicate references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non-
blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different
object reference to the file must be obtained by issuing an additional open(2) call. The close-on-exec flag on the new file descriptor is
unset.
In the second form of the call, the value of newd desired is specified. If this descriptor is already in use, the descriptor is first
deallocated as if a close(2) call had been done first.
RETURN VALUE
The value -1 is returned if an error occurs in either call. The external variable errno indicates the cause of the error.
ERRORS
Dup and dup2 fail if:
[EBADF] Oldd or newd is not a valid active descriptor
[EMFILE] Too many descriptors are active.
SEE ALSO
accept(2), open(2), close(2), fcntl(2), pipe(2), socket(2), socketpair(2), getdtablesize(2)
4th Berkeley Distribution May 13, 1986 DUP(2)