Modify a perl script to find and count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify a perl script to find and count
# 1  
Old 03-31-2009
Modify a perl script to find and count

Hello all !I have two sets of folders that have IP address from two sources.The below perl script I was working with needs some corrections.I am looking for the perl script to identify and count what IP address are found to be duplicated between both files.The format from both files are the same meaning IP addresses100.100.100.2
I am hopefull to get a report like so:
The report should contain a list of objects found in both datasets. For example:

"The following objects were found in both file A and File B:
10.1.1.1
10.2.2.1

With what I have I noticeing an error off the bat. Mind you I am not an expert in perl

syntax error at E:\dup2.pl line 10, near "print"Execution of E:\dup2.pl aborted due to compilation errors.
Thanks


#!perl

@ARGV=<E://rich//file-A-obj_prof.out.txt E://rich2//File-B-obj_prof-out.txt *>;
while( <> ){
next if /^#/;
print if $count{(split)[-1]}{$ARGV}++;
}
my %in;
push @{$in{join' and ',sort keys %{$count{$_}}}},$_ for sort grep{%{$count{$_}} > 1} keys %count
print join"\n","the following files appear in $_",@{$in{$_}},"" for keys %in;

Last edited by richsark; 03-31-2009 at 12:47 PM.. Reason: text format
# 2  
Old 03-31-2009
You might need a semi-colon at the end of line #9.
# 3  
Old 03-31-2009
Assuming your file parsing bits are good, maybe this will work:

Code:
#!perl

my @dups;
my %seen;
@ARGV = ('E://rich//file-A-obj_prof.out.txt', 'E://rich2//File-B-obj_prof-out.txt');
while( <> ){
   next if /^#/;
   chomp;
   my $ip = (split)[-1];
   push @dups, $ip if (++$seen{$ip} == 2);    
}
for (sort @dups) {
   print "$_\n";
}

# 4  
Old 04-01-2009
OK, it works !

But can it have a count or some words at the bottom that like

"The following objects were found in both file A and File B:
10.1.1.1
10.2.2.1
# 5  
Old 04-01-2009
Quote:
Originally Posted by richsark
OK, it works !

But can it have a count or some words at the bottom that like

"The following objects were found in both file A and File B:
10.1.1.1
10.2.2.1
I am sure you could. What have you tried so far to solve that requirement?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[perl script] print the assembly instruction and count the occurence

Hi, I have a input file(text file) with the following lines. 0x000000 0x5a80 0x0060 BRA.l 0x60 ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:24 0x000002 0x1bc5 RETI ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:30 0x000003 0x6840 MOV R0L,R0L ;file:UserCall.s... (6 Replies)
Discussion started by: acdc
6 Replies

2. Shell Programming and Scripting

Perl script to modify csv file

Hi Friends, I want to convert a csv file into a ordinary .txt file. I am able to convert but I want the output to look as shown below in the .txt file table findhost= { {"xyz","abc"}, {"rxz","mmz"}, {"vrr","nnz"}, } default={"NONE"} My current perl script #!/usr/bin/env perl... (12 Replies)
Discussion started by: dbashyam
12 Replies

3. Shell Programming and Scripting

count number of entries perl program or Unix script

Hi I have a file with number of entries name 1 123 name 1 345 name 1 65346 name2 3243 name2 24234 name 2 234234 so on ......... how to count total number of entries for name 1 and name2...and so on Please guide. (1 Reply)
Discussion started by: manigrover
1 Replies

4. Shell Programming and Scripting

Perl - need script for modify lines

Hello, does somebody can make script for me, which replace: ąćę ąćę ąćę (input file) to ace;|;ąćę ace;|;ąćę ace;|;ąćę (output file) (3 Replies)
Discussion started by: Xadrian
3 Replies

5. Shell Programming and Scripting

How to find the count and replace the particular part of string in perl?

Hi, I am taking the current time using localtime function in perl. For example if the time is: #Using localtime $time = "12:3:10"; I have to replace the value 3 (03) i.e second position to be 03. The output should be: 12:03:10 But if the other string for example: $str:... (1 Reply)
Discussion started by: vanitham
1 Replies

6. Shell Programming and Scripting

perl script on how to count the total number of lines of all the files under a directory

how to count the total number of lines of all the files under a directory using perl script.. I mean if I have 10 files under a directory then I want to count the total number of lines of all the 10 files contain. Please help me in writing a perl script on this. (5 Replies)
Discussion started by: adityam
5 Replies

7. Shell Programming and Scripting

Modify Perl Script To Send Attachments

Hello, I'm a newbie to the world of programming and so i decided to take up perl. I'm trying to learn how to modify the script below in order to have it sent with attachments. Any suggestions? #!/usr/bin/perl -w use strict; use warnings; my $from = 'xxx@domain.com'; my $to =... (0 Replies)
Discussion started by: xmaverick
0 Replies

8. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

9. UNIX for Dummies Questions & Answers

Perl/shell script count the lines

Hi Guys, I want to write a perl/shell script do parse the following file input file content NPA-NXX SC 2084549 45 2084552 45 2084563 2007 2084572 45 2084580 45 3278411 45 3278430 45 3278493 530 3278507 530... (3 Replies)
Discussion started by: pistachio
3 Replies

10. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies
Login or Register to Ask a Question