Need a script for intelligent diff


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a script for intelligent diff
# 1  
Old 05-11-2012
Need a script for intelligent diff

Hi, I have 2 files which represent data in a Sybase table and I need to run a diff on them, and based on the first column (which is the primary key) in each file, create 3 files, one for inserts, one for deletes and one for updates

Example:
old.txt contains
Code:
server1,a,b,c
server2,d,e,f
server4,j,k,l
server5,m,n,o

new.txt contains
Code:
server2,a,b,c
server3,g,h,i


So the output files would be:
delete.txt
Code:
server1,a,b,c
server4,j,k,l
server5,m,n,o

insert.txt
Code:
server3,g,h,i

update.txt
Code:
server2,a,b,c


So far I have something which puts the output into a single file with a delta code of I or D, but I can't figure out how to get the U part.


Any help would be appreciated!

Thanks

Last edited by joeyg; 05-11-2012 at 02:42 PM.. Reason: Please use CodeTags around example data and scripts
# 2  
Old 05-11-2012
Question Need more info

What is the input file?
What are the rules for the various files?
Not clear from your description.
# 3  
Old 05-11-2012
The input files are old.txt and new.txt - they contain text that represents data in a Sybase table with the first columns being the primary key. Based on that, I want to run a diff / awk / sed script which will compare the rows in the two files and produce a file with the inserts (rows that exist in new.txt but not old.txt), deletes (rows that exist in old.txt but not new.txt) and updates (rows that exist in both but have different data besides the primary key)

Hope that helps. Thanks
# 4  
Old 05-11-2012
Have you looked at

Code:
comm
diff

commands?
# 5  
Old 05-11-2012
I don't have them yet, that's why I'm posting here. I want to know if anyone has any existing code which will do this, perhaps with a combination of diff, awk, sed, etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. Shell Programming and Scripting

Intelligent Script to Insert Records in Database Table

Hello All Members, I am new to this forum and to the shell scripting. I want to write a shell script to do the following: Scenario: I have a pipe delimited .txt file with multiple fields in it. The very first row of the file contains the name of the column which resembles the name of the... (18 Replies)
Discussion started by: chetanojha
18 Replies

3. Shell Programming and Scripting

[Solved] intelligent splitting?

Hi, I want to split a file into multiple ones, with a new file for every line in the old file. Typically it is in this format 0.25 20 35.7143 0.5 31 55.3571 0.85 3 5.35714 1.3 2 3.57143 I can make new files by using split or other simple awk commands. But sometimes, the file is like... (7 Replies)
Discussion started by: jamie_123
7 Replies

4. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

5. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

6. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

7. UNIX for Dummies Questions & Answers

A more intelligent SDIFF

Hi all I have two files which are essentially the same. However the way an exponent is written is different (i.e. in 1 file, a particular number might be written as 1.43230000E+02 whereas in another it might be 1.4323E2). If I use SDIFF then the program will merely check the ASCII characters... (1 Reply)
Discussion started by: robbiegregg
1 Replies

8. Shell Programming and Scripting

more intelligent way of uninstalling a RPM

Hi all, I'm writing an uninstaller for a bespoke piece of software that we deploy to our Linux terminals. One of the packages we install is the JDK (Java Development Kit). Now over the years we have quite a number of different versions installed with different package names. In my uninstaller... (0 Replies)
Discussion started by: _Spare_Ribs_
0 Replies

9. 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