difference between 2 files in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers difference between 2 files in unix
# 1  
Old 01-26-2011
difference between 2 files in unix

I need the get the difference between 2 files and the result, I need to output it to an other file
file1
1
1
2
file2
1
1
2
3
Result....File3=3
used diff file1 file2 > file3 ( not working as expected)..Exact requirement..I have 2 flatfiles to compare and load only the difference in a table.

Please suggest...Thanks
win4luv
# 2  
Old 01-26-2011
Are they always going to be in order like this?

---------- Post updated at 02:31 PM ---------- Previous update was at 02:26 PM ----------

Code:
$ diff a b
3a4
> 3
$ diff a b | grep "^>" | sed 's/^> //'
3
$


Last edited by Corona688; 01-26-2011 at 04:33 PM.. Reason: pointless 'tail'
# 3  
Old 01-27-2011
difference between 2 files in unix

Thanks for the prompt reply... These are log files actually..So i believe while using diff one has to sort data first..But i would try this and update..

---------- Post updated at 05:08 AM ---------- Previous update was at 01:24 AM ----------

Warning: missing newline at end of file testfile1.log
Warning: missing newline at end of file testfile2.log
2
3


Thats is what gets displayed..Also, the result shud go to a new file..

Please suggest
win4luv
# 4  
Old 01-27-2011
Maybe this is what you mean?

Code:
cat testfile1.log testfile2.log | sort | uniq -u > mydifferences.log

# 5  
Old 01-27-2011
try very easy:

Code:
 
diff file1 file2 | tail +2 | cut -d">" -f2

# 6  
Old 01-27-2011
@GERMANICO - I'm afraid that your code does not work. Try running it with more than one difference or records containing spaces. Any approach using "diff" will be very difficult to implement.

@win4luv
If you need to know which file contained the difference it is better to sort each file and the run the unix "comm" command twice with different parameters on the sorted files.
One reason you might want the "comm" approach is could be if you need to distinguish deleted records from new records.
# 7  
Old 01-27-2011
Difference between two files

Methyl: your idea did not fetch me the required result..The result what i got is

2
21
3

Can you please let me know abt the sort thing which you are talking about?

Appreciate your help.
win4luv
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. UNIX for Dummies Questions & Answers

difference between unix and linux

Hi I am new to linux I have dout waht is the difference between UNIX and LINUX Is there any soft for insatallation for UNIX OS Thanks (0 Replies)
Discussion started by: sanjaya
0 Replies

3. Shell Programming and Scripting

Difference Between 2 files in UNIX

Hi, I am having files in the below format $ cat a.txt 1, abc, 1234 2, bcd, 2345 $ cat b.txt 1, bcd, 2345 2, cde, 3456 and I want to display only what is not exists in a.txt through UNIX script. like 2, cde, 3456 Please advice me. (1 Reply)
Discussion started by: Alex_Smith
1 Replies

4. UNIX for Dummies Questions & Answers

Difference between windows and Unix

Hi all, can anyone share any URl or link which is about the main 20 advantages and features of unix over windows i mean i need camparison matrix between windows and any flavour of unix. thanks a lot in advance for sharing. Best Regards (4 Replies)
Discussion started by: younusdba
4 Replies

5. Solaris

difference between unix and genunix files

Hi, Please explain difference between unix and genunix files in solaris. Thanks in advance (4 Replies)
Discussion started by: bpsunadm
4 Replies

6. UNIX for Dummies Questions & Answers

Unix difference

Hi, What is the difference between the following unix ie.. Linux-unix, HP-Unix, AIX, Solaris Unix... whether commands used in all unix are same? and which one is best?..... (2 Replies)
Discussion started by: gwgreen1
2 Replies

7. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

OK, I've used various versions of UNIX(Solaris, HPUX, etc..) over the years. Now the organization I work for is leaning towards more Linux based systems(Redhat, Suse, etc..) I do see differences in in comands and how to accomplish basic adminstration, but nothing mind blowing. So, what is it... (5 Replies)
Discussion started by: pbonilla
5 Replies

8. UNIX for Dummies Questions & Answers

difference between unix and linux?

Ok, I'm confused. Can someone answer these (stupid) questions please for me? 1. What is the difference between unix and linux? 2. Is FreeBSD a unix distribution? 3. If not, then what is Unix? I actually gone to Unix.com because I thought this is it's official website where I could download... (1 Reply)
Discussion started by: RellioN
1 Replies

9. UNIX for Dummies Questions & Answers

Difference between UNIX operating system and Unix Open Server

Hi, I recently joined this forum and new to UNIX. Is there any difference between UNIX operating system and UNIX open server? Please explain. (1 Reply)
Discussion started by: Manjit
1 Replies
Login or Register to Ask a Question