Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Folks,

i have 2 files (file1.txt and file2.txt). i have to check which things are newly added in file2.txt. so i am using grep function to check whether it is already there. but it is not matching exact string. anyone have any idea?

file1.txt contains

nt64osbld2tmp vm-nt64osbld2 vm-nt64osbld3 vm-nt64osbld4 vm-nt64osbld5 vm-nt64osremot1 vm-nt64osremot2 vm-nt64osremot3 vm-nt64osremot4 vm-nt64osremot5 vm-nt64osremot6 vm-nt64osremot7 vm-nt64osremot8 vm-ntdivakar1 vm-ntdivakar2 vm-ntdivakar4 vm-ntosbld1 vm-ntosbld5 vm-ntoscert3 vm-ntosdev1 vm-ntskommare1 vm-ntskommare2 vm-ntskommare4 vm-os2k8r264-01 vm-osremote1 vm-osremote10 vm-osremote2 vm-osremote3 vm-osremote4 vm-osremote5 vm-osremote6 vm-osw2k8-1 vm-osw2k8-2 vm-oswin2k3-32 vm-oswin2k3-64

file2.txt contains
nt64osbld2 nt64osbld2tmp nt64osbld3 nt64oscitrix1 NTOSBLD4 ntosbld5 ntosbld6 VM-NT64OSBLD2 VM-NT64OSBLD3 VM-NT64OSBLD4 VM-NT64OSBLD5 vm-nt64osremot1 vm-nt64osremot2 vm-nt64osremot3 vm-nt64osremot4 vm-nt64osremot5 vm-nt64osremot6 VM-NT64OSREMOT7 VM-NT64OSREMOT8 vm-ntosbld1 VM-NTOSBLD5 vm-ntoscert3 vm-ntosdev1 VM-OS2K8R264-01 vm-osremote1 vm-osremote10 vm-osremote2 vm-osremote3 vm-osremote4 VM-OSREMOTE5 vm-osremote6 VM-OSW2K8-1 VM-OSW2K8-2 VM-OSW2K8X64-1 VM-OSW2K8X64-2 VM-OSWIN2K3-32 VM-OSWIN2K3-64

below is my script.
use warnings; use strict; my @first_list; my @second_list; my @first_list_new; my @second_list_new; open FIRST_LIST, "< first_list.txt" or print $! "\n"; @first_list=<FIRST_LIST>; close (FIRST_LIST); chomp (@first_list); open SECOND_LIST, "< second_list.txt" or print $! "\n"; @second_list=<SECOND_LIST>; close (SECOND_LIST); chomp (@second_list); foreach my $machine (@first_list) { my $machine_new=lc($machine); push(@first_list_new,$machine_new); } foreach my $machine (@second_list) { my $machine_new=lc($machine); push(@second_list_new,$machine_new); } print "Machines extra in second list\n\n"; foreach my $unique (@second_list_new) { if (grep (/^$unique$/,@first_list_new)) { print "already there $unique\n\n"; } else { print "newly in this $unique\n\n"; } }

Thanks & Regards,


In reply to How to grep exact string by Divakar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [marioroy]: msg choraba Maybe soon will have a job. My spirit is good.
    [marioroy]: ;-) was met for choroba.

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (9)
    As of 2018-03-22 18:20 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (282 votes). Check out past polls.