Operating System - HP-UX
1833823 Members
2417 Online
110063 Solutions
New Discussion

Re: Doing diff on portions of files

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Doing diff on portions of files

HI,

I have 2 files, file1 and file2 with the following contents:
fil1:
const int errBuffLen=30;
static char errBuff[errBuffLen+1];
String lastMsg;

error::genmessagef(){
...
}

error::genmessage(){
...
}

error::getType(){
...
}

file2:
logfile::msg(){
...
}

logfile::genmessagef(){
...
}

logfile::genmessage(){
...
}

logfile::logging(){
...
}

I'm interested to list only the differences of the files containing the portions genmessage(){...} and genmessagef(){...} contained in files file1 and file2. i.e I'd like to see the differences of the functions genmessage(){...} and genmessagef(){...} in file1 and file2.

I was wondering how do I use #diff to specify the patterns which I want to search for its difference within files? Or is there any other method/scripts which need to use?

Could someone kindly show me how it's done?

Thanks



4 REPLIES 4
maria paschali
Frequent Advisor

Re: Doing diff on portions of files

Hi,

I dont know if this will help you or not, but I generally use sdiff to view files side by side.

do a man on sdiff and see if this is what you want.

alternatively you can use diff -s which sort of does the same thing but doesn't list them side by side.

I hope this has helped you somewhat.

Cheers
Maria
John Poff
Honored Contributor

Re: Doing diff on portions of files

Hi,

I think you could write a Perl script that would use some regular expressions to pull the the parts you want to compare. I've been playing with it but I haven't gotten it right yet. Maybe some of the resident Perl wizards will see this and post a clever way to do it.

JP
Jean-Louis Phelix
Honored Contributor
Solution

Re: Doing diff on portions of files

Hi,

I think that you have to generate tmpfiles using for example :

#awk '/^logfile::genmessagef(){/,/^}/' f1 > o1
#awk '/^logfile::genmessagef(){/,/^}/' f2 > o2
#diff o1 o2

Regards.
It works for me (© Bill McNAMARA ...)
H.Merijn Brand (procura
Honored Contributor

Re: Doing diff on portions of files

Diff related perl modules will save you a lot of time when you are to try it in perl:

http://search.cpan.org/search?query=diff&mode=all will show


?? http://search.cpan.org/author/RBS/Text-Diff-0.35/
?? http://search.cpan.org/author/NEDKONZ/Algorithm-Diff-1.15/
Enjoy, Have FUN! H.Merijn