Formatting output of diff command
Hello, I'm having problems with the output of the diff command. I'm doing something like this in a shell script:
/usr/bin/diff -y --suppress-common-lines file1 file2 This produces an output like: azdatetime.h 1.5 17-JAN-2012 11:19:03 TMCKNIGH | azdatetime.h,v 1.3 2004/04/01 15:42:56 cyang azdevice.h 1.2 16-JUL-2008 09:59:36 THUTCHIN | az.h,v 1.17 2004/07/19 15:09:40 lthornto az.h 1.21 30-JUN-2008 23:52:14 THUTCHIN | azi18n.h,v 1.5 2004/04/27 14:03:16 cgeigel azi18n.h 1.7 15-APR-2010 11:11:14 DCAIN < azstore.h 1.15 10-MAR-2009 13:25:38 JMARX | azstore.h,v 1.10 2004/06/21 16:03:10 rgajula azstring.h 1.8 09-APR-2010 06:16:58 DCAIN | azstring.h,v 1.5 2004/04/01 15:43:58 cyang azui.h 1.10 29-JUL-2008 09:02:19 MROBSON | azui.h,v 1.6 2004/08/18 21:56:39 jwilliam I use this information to compare versions of the files, doing a cut of the fields I'm interested in, but as you can see, when there is one module that is not present in file2 (azdevice.h for example), the output is moved, so for example, now line azi18n.h from file1 doesn't correspond anymore to the one showing for file2. I need to compare versions of the same modules but I can't make the output of diff to display lines side by side, but respecting line order. I hope I was able to explain myself and you have some suggestions to try. Thanks in advance |
As you see above "azi18n.h 1.7 15-APR-2010 11:11:14 DCAIN <" does not have a corresponding line in the second file. So, do you want to include it in your report too or not?
If not then, you can exclude such lines: Code:
/usr/bin/diff -y --suppress-common-lines file1 file2 | grep -v '<$' Code:
/usr/bin/diff -y --suppress-common-lines file1 file2 | grep ' | ' |
Thanks for the quick reply devUnix.
I do need lines that are not present in one of the two files, I'll do something like New Module found or Module deleted with those. Basically what I'm having problems with is the non correspondence of lines with similar output. I'm trying to do something like this: azdatetime.h 1.5 17-JAN-2012 11:19:03 TMCKNIGH | azdatetime.h,v 1.3 2004/04/01 15:42:56 cyang azdevice.h 1.2 16-JUL-2008 09:59:36 THUTCHIN | az.h,v 1.17 2004/07/19 15:09:40 lthornto az.h 1.21 30-JUN-2008 23:52:14 THUTCHIN | azi18n.h,v 1.5 2004/04/27 14:03:16 cgeigel azi18n.h 1.7 15-APR-2010 11:11:14 DCAIN < azstore.h 1.15 10-MAR-2009 13:25:38 JMARX | azstore.h,v 1.10 2004/06/21 16:03:10 rgajula azstring.h 1.8 09-APR-2010 06:16:58 DCAIN | azstring.h,v 1.5 2004/04/01 15:43:58 cyang azui.h 1.10 29-JUL-2008 09:02:19 MROBSON | azui.h,v 1.6 2004/08/18 21:56:39 jwilliam Into something like this: azdatetime.h 1.5 17-JAN-2012 11:19:03 TMCKNIGH | azdatetime.h,v 1.3 2004/04/01 15:42:56 cyang azdevice.h 1.2 16-JUL-2008 09:59:36 THUTCHIN < az.h 1.21 30-JUN-2008 23:52:14 THUTCHIN | az.h,v 1.17 2004/07/19 15:09:40 lthornto azi18n.h 1.7 15-APR-2010 11:11:14 DCAIN | azi18n.h,v 1.5 2004/04/27 14:03:16 cgeigel azstore.h 1.15 10-MAR-2009 13:25:38 JMARX | azstore.h,v 1.10 2004/06/21 16:03:10 rgajula azstring.h 1.8 09-APR-2010 06:16:58 DCAIN | azstring.h,v 1.5 2004/04/01 15:43:58 cyang azui.h 1.10 29-JUL-2008 09:02:19 MROBSON | azui.h,v 1.6 2004/08/18 21:56:39 jwilliam Probably I cannot do it with diff and need to parse both files manually, but hopefully diff can be my answer. Thanks |
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
I'm not sure I understand your requirements exactly, and I'm not an expert in diff anyway, but you may want to try reading the info page for it, as it goes into much more detail than the man page. It might also help if you gave us some example input text of the two files you are comparing, as well as how exactly you want the output of it to look. |
Ok, I'll try to provide the example of the text files.
File 1 has: Code:
azcache.h,v 1.3 2004/04/01 15:42:38 cyang Code:
azcache.h,v 1.3 2004/04/01 15:42:38 cyang Code:
/usr/bin/diff -y --suppress-common-lines file1 file2 Code:
azdatetime.h 1.5 17-JAN-2012 11:19:03 TMCKNIGH | azdatetime.h,v 1.3 2004/04/01 15:42:56 cyang Code:
azdatetime.h 1.5 17-JAN-2012 11:19:03 TMCKNIGH | azdatetime.h,v 1.3 2004/04/01 15:42:56 cyang I hope this was clearer. Thanks |
I was able to get my require output doing redirecting the output of the regular diff to a file and parsing this file.
This post can be closed. Thanks |
All times are GMT -5. The time now is 07:54 PM. |