The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing two files guptan Shell Programming and Scripting 5 08-04-2008 08:02 AM
Comparing two files... paqman Shell Programming and Scripting 12 08-08-2007 03:45 AM
Paste the files contents differently er_aparna Shell Programming and Scripting 1 05-16-2007 04:29 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 02:38 AM
comparing files to contents of a file SummitElse Shell Programming and Scripting 3 06-28-2006 12:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2007
rrs rrs is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 21
Comparing contents of files

Hi,
I hav two files a1.txt and a2.txt,

a1.txt contains:
---------------
asdev ebcdev ....

a2.txt contains:
---------------
asdev ebcdev prod ....
a1.txt will be updated by a process,..
now i want to compare two files and i want to see data which is not in a1.txt

am i clear....??

regards
leenus
  #2 (permalink)  
Old 04-03-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
search the forum
  #3 (permalink)  
Old 04-03-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by rrs
Hi,
I hav two files a1.txt and a2.txt,

a1.txt contains:
---------------
asdev ebcdev ....

a2.txt contains:
---------------
asdev ebcdev prod ....
a1.txt will be updated by a process,..
now i want to compare two files and i want to see data which is not in a1.txt

am i clear....??

Depending on what type of output you want, you could use com, diff or grep -f.

  #4 (permalink)  
Old 04-03-2007
mukundranjan mukundranjan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 20
Use this perl code for your solution

Code:
#!/usr/bin/perl

open(FILE, "<", "a1.txt" ) || die "Unable to open file a <$!>\n";
while ( <FILE> ) {
        chomp;
        $fileHash{$_} = $i++;
}
close(FILE);
open(FILE, "<", "a2.txt" ) || die "Unable to open file a <$!>\n";
while( <FILE> ) {
        chomp;
        if( exists $fileHash{$_} ) {
          }
        else {
                print "$_\n";
        }
}
close(FILE);
exit 0
Thanks,
Mukund Ranjan

Last edited by mukundranjan; 04-03-2007 at 08:15 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0