Click here to get back home

Comparing two files

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Comparing two files clearguy02 01-15-2008
|--> Re: Comparing two files Martijn Lievaar...01-15-2008
Posted by clearguy02 on January 15, 2008, 3:55 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Martijn Lievaart on January 15, 2008, 4:03 pm
Please log in for more thread options
On Tue, 15 Jan 2008 12:55:56 -0800, clearguy02 wrote:

> Hi folks,
>
> I have two files, one with 1000 lines and another with 600 lines and
> both files have the user login ID's and the first file has an extra of
> 400 user id's that I need to find.
>
> Here is the script I have written:
> ------------------------------------
> open (INPUT1,"fullFile.txt") or die "Cannot open the file: $!"; open
> (INPUT2,"comapreFile.txt") or die "Cannot open the file: $!";
>
> @array1 = <INPUT1>;
> @array2 = <INPUT2>;
>
> foreach $word (@array2)
> {
> if(!grep /$word/i, @array1)
> {
> print "$_\n";

What value is $_ here? Where is it set?

> }
> }
> ----------------------------------------
>
> I am not able to see the output on the screen. Any one sees where I am
> doing wrong?

You could have found this yourself if you added
use strict;
use warnings;
on the top of your script!

HTH,
M4

Posted by Jürgen Exner on January 15, 2008, 4:09 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by John W. Krahn on January 15, 2008, 4:19 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by clearguy02 on January 15, 2008, 4:51 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Similar ThreadsPosted
Comparing XML files August 8, 2005, 6:22 pm
Comparing two files April 7, 2008, 6:07 pm
Comparing huge XML Files February 23, 2005, 1:14 am
Comparing 2 XML files need some suggestions please April 15, 2005, 7:14 am
comparing modification times of files September 13, 2006, 11:10 am
Diff files with regex comparing May 13, 2007, 11:40 am
Parsing two files and comparing the first fields.. November 28, 2007, 6:12 pm
Comparing 2 dates ? December 20, 2004, 9:41 am
comparing two numbers March 4, 2005, 1:37 pm
comparing two dates July 29, 2005, 2:02 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap