Find diff bet 2 files and store result in another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find diff bet 2 files and store result in another file
# 1  
Old 04-07-2010
Find diff bet 2 files and store result in another file

Hi
I want to compare 2 files. The files have the same amount of rows and columns. So each line must be compare against the other and if one differs from the other, the result of both must be stored in a seperate file.
I am doing this in awk.

Here is my file1:
Code:
 
Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B

Here is my file 2:

Code:
 
Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B

Duplicate data may be ignored, so resultant file is:

Code:
Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B


Here is my script:

Code:
 
awk -F',' -v file1="$1" -v file2="$2" '{print;}1' OFS="," diff $1 $2 > resultfile.csv

Can you help me please.
# 2  
Old 04-07-2010
Did not get any idea to do it in a short way,

But this will be fine:

Code:
 
diff  File1 File2 | awk '/Blocks/' | sed -e 's/<//g' -e 's/>//g' | sort -u

# 3  
Old 04-07-2010
Thank you. This works great,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

2. Shell Programming and Scripting

Padding diff result

Hi, Is there a way to add padding to a diff result in unix so number of "< .." lines will be equal to number of "> .." lines? For example, if the original result is: 9a10 > "line which exists only in one file" The changed result would be: 9a10 < "noMatch" --- > "line which exists... (5 Replies)
Discussion started by: Somename
5 Replies

3. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

4. UNIX for Dummies Questions & Answers

Find diff between two patterns in two files and append

Hi, I'm a newbie at programming in Unix, and I seem to have a task that is greater than I can handle. Trying to learn awk by the way (but in the end, i just need something that works). My goal is to compare two files and output the difference between the two. I've been reading, and I think I... (5 Replies)
Discussion started by: legato22
5 Replies

5. Shell Programming and Scripting

Search file for string and store last result to variable

Hi, I'm trying to search a text file for a string: "energy(sigma->0)=". To do so, I executed the grep command, which returned many matches, for example: energy without entropy = -112.16486170 energy(sigma->0) = -112.16520778 energy without entropy = -112.16488936 ... (5 Replies)
Discussion started by: gwr
5 Replies

6. Shell Programming and Scripting

compare two files, diff the result

Hi Everyone, 1.txt 00:01:01 asdf 00:33:33 1234 00:33:33 0987 00:33:33 12 00:33:33 444 2.txt vvvv|ee 444|dd33|ee dddd|ee 12|ee 3ciur|fdd the output should be: (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

8. Shell Programming and Scripting

Find duplicates from multuple files with 2 diff types of files

I need to compare 2 diff type of files and find out the duplicate after comparing each types of files: Type 1 file name is like: file1.abc (the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations). The other file is file1.bcd01abc (the extension... (2 Replies)
Discussion started by: ricky007
2 Replies

9. Shell Programming and Scripting

ls -R and then diff on those result

Hi, I have two similar directory structures. One is the latest dev environment and the other is a previous version of the same dev environment. I need to do a diff on the .cpp .c .java and .h files. Hence I need a list of all the files of the above pattern so that I can diff then... (3 Replies)
Discussion started by: vino
3 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question