Sponsored Content
Top Forums Shell Programming and Scripting Modify a perl script to find and count Post 302302602 by richsark on Tuesday 31st of March 2009 11:46:12 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
MooseX::AttributeHelpers::MethodProvider::List(3pm)	User Contributed Perl Documentation    MooseX::AttributeHelpers::MethodProvider::List(3pm)

NAME
MooseX::AttributeHelpers::MethodProvider::List - method generator for MooseX::AttributeHelpers::Collection::List SYNOPSIS
package Stuff; use Moose; use MooseX::AttributeHelpers; has 'options' => ( metaclass => 'Collection::List', is => 'rw', isa => 'ArrayRef[Str]', default => sub { [] }, auto_deref => 1, provides => { elements => 'all_options', map => 'map_options', grep => 'filter_options', find => 'find_option', first => 'first_option', last => 'last_option', get => 'get_option', join => 'join_options', count => 'count_options', empty => 'do_i_have_options', sort => 'sorted_options', } ); no Moose; 1; DESCRIPTION
This is a role which provides the method generators for MooseX::AttributeHelpers::Collection::List. METHODS
meta PROVIDED METHODS
count Returns the number of elements in the list. $stuff = Stuff->new; $stuff->options(["foo", "bar", "baz", "boo"]); my $count = $stuff->count_options; print "$count "; # prints 4 empty If the list is populated, returns true. Otherwise, returns false. $stuff->do_i_have_options ? print "Good boy. " : die "No options! " ; find This method accepts a subroutine reference as its argument. That sub will receive each element of the list in turn. If it returns true for an element, that element will be returned by the "find" method. my $found = $stuff->find_option( sub { $_[0] =~ /^b/ } ); print "$found "; # prints "bar" grep This method accepts a subroutine reference as its argument. This method returns every element for which that subroutine reference returns a true value. my @found = $stuff->filter_options( sub { $_[0] =~ /^b/ } ); print "@found "; # prints "bar baz boo" map This method accepts a subroutine reference as its argument. The subroutine will be executed for each element of the list. It is expected to return a modified version of that element. The return value of the method is a list of the modified options. my @mod_options = $stuff->map_options( sub { $_[0] . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" sort Sorts and returns the elements of the list. You can provide an optional subroutine reference to sort with (as you can with the core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" elements Returns all of the elements of the list my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" join Joins every element of the list using the separator given as argument. my $joined = $stuff->join_options( ':' ); print "$joined "; # prints "foo:bar:baz:boo" get Returns an element of the list by its index. my $option = $stuff->get_option(1); print "$option "; # prints "bar" first Returns the first element of the list. my $first = $stuff->first_option; print "$first "; # prints "foo" last Returns the last element of the list. my $last = $stuff->last_option; print "$last "; # prints "boo" BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2007-2009 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-01-02 MooseX::AttributeHelpers::MethodProvider::List(3pm)
All times are GMT -4. The time now is 11:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy