compare files
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > compare files




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    compare files  
tester


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-21-06 06:27 AM

Hi Gurus,
i am looking for script wherein compare two files and generate a third
file which has output from one file  which is not present on other.

e.g. file1 and file2 -> file3

file3 should have all the contents form file1 which is not there in
file2.

I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
it doesn't contain the output lokking for.
Any help is greatly appreciated
TIA






[ Post a follow-up to this message ]



    Re: compare files  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-21-06 06:27 AM

On 2006-10-21, tester wrote:
> Hi Gurus,
> i am looking for script wherein compare two files and generate a third
> file which has output from one file  which is not present on other.
>
> e.g. file1 and file2 -> file3
>
> file3 should have all the contents form file1 which is not there in
> file2.
>
>  I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.

comm -13 file1 file2 > file3

comm -23 file1 file2 > file3

--
Chris F.A. Johnson, author        <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence





[ Post a follow-up to this message ]



    Re: compare files  
Robert Katz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-21-06 06:27 AM

tester wrote:
> Hi Gurus,
> i am looking for script wherein compare two files and generate a third
> file which has output from one file  which is not present on other.
>
> e.g. file1 and file2 -> file3
>
> file3 should have all the contents form file1 which is not there in
> file2.
>
>  I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.
> Any help is greatly appreciated
> TIA
>


If you want all the lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a)' file2 file1

If you want only uniq lines in file1 that are not in file2,
awk 'NR == FNR { a[$0]; next } !($0 in a) { print; a[$0] }
' file2
file1

--
Regards,

---Robert





[ Post a follow-up to this message ]



    Re: compare files  
Michael Paoli


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-22-06 12:31 AM

tester wrote:
> i am looking for script wherein compare two files and generate a third
> file which has output from one file  which is not present on other.
> e.g. file1 and file2 -> file3
> file3 should have all the contents form file1 which is not there in
> file2.
>  I did sorted file1 and file2 and ran comm -3 file1 file2 > file3 but
> it doesn't contain the output lokking for.

Have a look here:
news:1158818522.030928.321780@m73g2000cwd.googlegroups.com






[ Post a follow-up to this message ]



    Re: compare files  
tester


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-23-06 06:16 PM


Thanks Michael Paoli..
That Helped....

> Have a look here:
> news:1158818522.030928.321780@m73g2000cwd.googlegroups.com






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:07 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register