Solved

Search and Compare between 2 Files and writing the results into another file.

Posted on 2008-10-02
1
276 Views
Last Modified: 2013-11-17
Hello,

I have 2 files. Both of these files have XML formats.

First File has Single Line XML Requests and second file has single line XML OutPuts.

Every Request Line has an ID associated to it and the corresponding response will have the same ID in it.

Now the problem is to separate those request lines from the Request File which has no corresponding success response in the Response File.

There fields in the XML which have ID And Status Information in the same line.  

<Id>123</ID> ...... <Status>Success</Status>

what this means is, For every Line in Request File, There will be a ID Filed, whose value will uniquely identify that request. This Id needs to be searched in the Response File, If I find that ID, in the same Line I should Find the <Status>Success</Status>.

If I do not find the Id at all in the Response File or After finding the Id, the <Status>Success</Status> is not found in the same line, then the Corresponding Line from the REQUEST FILE need to be copied into a FailedRequestsFile.

So I hope the description I gave explains that this is all about filtering the requests which failed to retuning a response at all or returned a Fail response. so that we can reprocess them.

thank you.
0
Comment
Question by:objectkk
1 Comment
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 22626364
It would help if you posted both XML files... but going on your description so far

open(my $in, "<response_file_here.txt") or die "Could not open response: $!\n";

my %Res;

while(<$in>) {

	next unless m|<id>(\d+).*<Status>(.*?)</Status>|;

	$Res{$1} = $2;

}

close($in);
 
 

open($in, "<request_file_here.txt") or die "Could not open requests: $!\n";

open(my $out, ">failed_requests.txt") or die "Could not open failed requests: $!\n";

while(<$in>) {

	next unless /<id>(\d+)/;

	print $out $_ unless($Res{$1} and $Res{$1} eq 'Success');

}

close($out);

close($in);

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl modules on linux ec2 3 96
Can I delete authorized_keys in FreeBSD 1 78
Ned Perl Snippet to Read Files in Directory 5 62
Export Variables in Perl 3 46
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now