Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    21

    Unanswered: Compare files and update

    How do I do this

    I have two files:
    file1.txt
    10-9-2004|client1|Linux|Greg hart
    10-8-2004|client1|PC|Greg Door
    10-9-2004|Client2|HP|Joe Aullay
    1-7-2004|client6|HP|Peet Keven

    file2.txt
    For client1 Linux from Greg Hart|info 2xx|13/09/2004
    For client6 HP from Peet Keven|db2 4xx|10/09/2004

    I want to update my file1.txt if file2.txt contain
    1- the same name (example Greg hart or ...)
    2- the same client name
    3- the operating system name
    and if any above condition did not apply on any lines append the line by |-|

    The result will be

    10-9-2004|client1|Linux|Greg hart|info 2xx|13/09/2004
    10-8-2004|client1|PC|Greg Door|-|-
    10-9-2004|Client2|HP|Joe Aullay|-|-
    1-7-2004|client6|HP|Peet Keven|db2 4xx|10/09/2004


    This is my script
    I need to use filed matching for every line in file

    #! /perl/bin/perl

    use strict;

    open(FILE2,"<file2.txt");
    my @file2=<FILE2>;
    close FILE2;

    open(FILE1,"<file1.txt");
    my @file1=<FILE1>;
    close FILE1;



    foreach my $line (@file2) {
    my ($firstfield,$system,$date) = split(/\|/,$line);
    #print "$firstfield,$system,$date";

    my @names = split/ /,$firstfield;
    my $client_file2 = "$names[1]";
    my $os_file2 = "$names[2]";
    my $names = "$names[4] $names[5]";

    #print "$client_file2, $os_file2, $names\n";

    foreach my $f1_line (@file1) {
    my ($f1_date,$f1_cust,$f1_os,$f1_name) = split(/\|/,$f1_line);
    #print "$f1_date,$f1_cust,$f1_os,$f1_name";

    #if(($f1_cust eq $client_file2) && ($f1_os eq os_file2))
    {
    print "MATCH found IN FILE1 for $f1_date,$f1_cust,$f1_os,$f1_name\n";
    }
    else{
    print "NO MATCH IN FILE1 for $f1_date,$f1_cust,$f1_os,$f1_name\n";
    }

    }

    }
    Last edited by melindaj; 09-21-04 at 20:12.

  2. #2
    Join Date
    Jun 2004
    Posts
    21
    Any one can help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •