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
to compare two files and to print the difference cdfd123 Shell Programming and Scripting 5 10-06-2007 04:55 AM
How to compare the difference between a file and a folder?? kumarsaravana_s UNIX for Dummies Questions & Answers 2 03-22-2007 03:07 AM
Strange difference in file size when copying LARGE file.. 0ktalmagik Filesystems, Disks and Memory 1 06-03-2006 07:34 PM
compare two .dat files and if there is any difference pulled into a separate file kirankumar Shell Programming and Scripting 1 04-19-2006 02:13 AM
Newbie question about difference between executable file and ordinary file Balaji UNIX for Dummies Questions & Answers 1 11-29-2000 06:49 AM

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

Join Date: Sep 2007
Posts: 4
compare 2 file and print difference in the third file URG PLS

Hi
I have two files in unix. I need to compare two files and print the differed lines in other file

Eg
file1
1111
2222
3333
file2
1111
2222
3333
4444
5555

newfile
4444
5555

Thanks In advance
  #2 (permalink)  
Old 09-24-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,860
Code:
comm -3 file1 file2>newfile
  #3 (permalink)  
Old 09-24-2007
evvander evvander is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 4
if I do this then extra space is getting added at begining of each line in new file
  #4 (permalink)  
Old 09-24-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,860
Code:
printf "%s\n" $(comm -3 file1 file2)>newfile
If the words/lines contain spaces:

Code:
rm newfile&&comm -3 file1 file2|while read;do printf "%s\n" "$REPLY">>newfile;done
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 01:44 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