One file contains values like
2000/01/03/aaa/xyz.xml
2002/04/01/bbb/abc.xml
Second file contains
2000/01/03/xyz
How to read the two files simultaneously and print the line if it is not present in file2 by spliting 4th field and .xml.
#!/usr/bin/perl
$data_file="/tmp/input_ext_id.txt";
open(DAT, $data_file) || die("Could not open file!");
@datas=<DAT>;
foreach $data(@datas){
$data_orig=$data;
@data=split("/",$data);
$data[4] =~ s/\.xml//ig;
chomp($data_orig);
push(@finalarr,"$data_orig#$data[0]/$data[1]/$data[2]/$data[4]");
push(@finalarr, "$data[0]/$data[1]/$data[2]/$data[4]");
}
@sorted_list = sort(@finalarr);
redirected to a files.
Then I am taking the difference of two files(first file after removing the 4th field and .xml)
The difference of the lines is passed as <FILE2>.
@datas=<FILE2>;
while ($line = <FILE1>) {
$position=rindex($line,"#")+1;
$lines = substr($line,$position);
#print $lines;
$lines =~ s/^\s//gi;
if ( grep( /$lines/,@datas) ) {
print "$line";
}
When the files contains the line of 230K,
it takes too long time and prints out the message "OUT of memory"
The output should print
2002/04/01/bbb/abc.xml
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.