How to make diff show differences one line at a time and not group them?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make diff show differences one line at a time and not group them?
# 8  
Old 01-11-2012
if the "+" or "-" at the start of your output line is important, ignore this post!


If the files are already in sorted order or you are prepared to sort the files for this purpose, then try the unix "comm" command. "man comm".


For the data sample posted there is a quick and dirty approach:

Code:
cat file1 file2|sort|uniq -u

line 3 diff
line 3 diff.
line 4 diff
line 4 diff.
line 5 diff
line 5 diff.

This User Gave Thanks to methyl For This Post:
# 9  
Old 01-11-2012
Thank you. The leading - and + are used to identify the entries coming from files and are important. I am going to try this and see if that works in all cases (I have multiple files that are being compared and reported).

Code:
comm -3 file1 file2 | sed 's/^/-/;s/^-\t/+/'

# 10  
Old 01-11-2012
Try this... you got to test it out... and yeah this is dirty!
Code:
diff -y --suppress-common-lines file1 file2 | sed 's/|[ \t]*/\n+/;s/^[ \t]*>[\t ]*/+/;s/\(.*\)</-\1/;s/^[^-+]/-&/'

--ahamed
# 11  
Old 01-11-2012
Ok, how about this one:

Code:
diff -y file1 file2 | grep '|' | sed 's/\s*|\s/\n/g' | awk '!(NR%2) {$0=$0"\n"} 1'
line 3 diff
line 3 diff.

line 4 diff
line 4 diff.

line 5 diff
line 5 diff.

# 12  
Old 01-12-2012
Thanks for all your help. There was a little gotcha with each approach so I ended up using colors to distinguish between the entries from the files.
# 13  
Old 01-12-2012
There has been considerable interest in this thread.

Please post your final solution. The colours (or colors for USA folks) component of the solution is intriguing.
# 14  
Old 01-30-2012
The script compares different type of files (properties files that have many stanzas, list of stanzas, files that contain crontab listing, ...)

It creates an HTML email and I simply have it create a table and mark lines that start with '-' in one color and the ones starting with '+' a different color. As I am expanding its use, it would be ideal to have diff report differences one line at a time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Shell Programming and Scripting

2 lists, show differences plus or minus

Not really sure how to accomplish this. If I have two lists with matching columns. Second column is different. I would like to show the differences plus/minus. list1 device1 5 decive2 10 decive3 10 device4 10 device5 10 device6 20 list2 device1 10 ... (1 Reply)
Discussion started by: mrlayance
1 Replies

3. Red Hat

User is a Part of a Group But Group Details Do Not Show the User

Hi, In the following output you can see the the user "richard" is a member on the team/group "developers": # id richard uid=10247(richard) gid=100361(developers) groups=100361(developers),10053(testers) but in the following details of the said group (developers), the said user... (3 Replies)
Discussion started by: indiansoil
3 Replies

4. UNIX for Dummies Questions & Answers

[diff] hide missing rows, show similar

Hi all! Having the following two csv files: file1 AAA;0000;RED CCC;9900;GREEN file2 AAA;0000;BLACK BBB;0099;BLU What's the correct syntax to hide only the missing rows (BBB,CCC) and show the rows that differ only with last field? I expect something like this: diff <options> file1... (2 Replies)
Discussion started by: Evan
2 Replies

5. UNIX for Dummies Questions & Answers

Group files by owner and show directory

Hello, i would like to find huge files and group them by owners. To find big files i use this command: ls -lR | sort -bnr +4 | head -n 75 which give me 75 biggest files, then i need to see in which subdirectory is every file. second thing i dont know is how to group those files by owner, could... (6 Replies)
Discussion started by: dealer1985
6 Replies

6. Shell Programming and Scripting

Show the diff in two files using awk

Hi, How can i use AWK or any other commands to find the difference between 2 files. File A aaa bbb ccc 111 222 File B aaa ccc 111 Output bbb 222 (6 Replies)
Discussion started by: gambit97
6 Replies

7. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies

8. Shell Programming and Scripting

Show entire lines with diff command

Hi, When I run the diff command using diff -yt file1 file2, I get the output in which original lines are truncated. I tried using -W switch with diff. However, that does not produce exact output as I want. Is it possible to show entire line of file1 and file2 in diff command's output? ... (8 Replies)
Discussion started by: jal_capri
8 Replies

9. UNIX for Dummies Questions & Answers

Differences between time command and usr/bin/time

I wondered if someone could point out the differences between the time commmand and usr/bin/time and the accuracy one might have over another. Also, is there a website or two a person could maybe link for me to describe the differences? Thank you for your time. (2 Replies)
Discussion started by: icedrake
2 Replies

10. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
Login or Register to Ask a Question