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?
# 1  
Old 01-11-2012
How to make diff show differences one line at a time and not group them?

Is there a way to tell diff to show differences one line at a time and not to group them? For example, I have two files:

file1:
Code:
line 1
line 2
line 3 diff
line 4 diff
line 5 diff
line 6
line 7

file2:
Code:
line 1
line 2
line 3 diff.
line 4 diff.
line 5 diff.
line 6
line 7

Code:
$ diff  -b -B -U 0 file1 file2
--- file1       2012-01-11 15:58:43.000000000 +0000
+++ file2       2012-01-11 15:59:14.000000000 +0000
@@ -3,3 +3,3 @@
-line 3 diff
-line 4 diff
-line 5 diff
+line 3 diff.
+line 4 diff.
+line 5 diff.

What I need is this:
Code:
-line 3 diff
+line 3 diff.
-line 4 diff
+line 4 diff.
-line 5 diff
+line 5 diff.

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-11-2012 at 12:13 PM.. Reason: code tags, please!
# 2  
Old 01-11-2012
diff is designed to detect insertions and deletions of lines, not just simple changes of lines, and that format would leave a lot desired for that; what you want isn't diff, exactly.

I don't understand where your output comes from, either. You seem to be showing the string 'diff' exists in both files when it does not...
# 3  
Old 01-11-2012
The string "diff" does exist in both files (I created the files to show an example). I realize that diff has the ability to provide differences for the purpose of merging files, I am not interested in that. I am creating a report from output of diff and am filtering out the additional information that diff provides (e.g. ---, +++, @@). The report would be much more useful if the differences were shown as one line at a time instead of being grouped. If there is another command/tool that I can use instead of diff for that I am open to it. Thanks.
# 4  
Old 01-11-2012
Not sure if this is on the path you're trying travel down, but is this along the lines of what you're trying to achieve?

Code:
diff -y file1 file2 | grep '|' | sed 's/\s*|//g'

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

# 5  
Old 01-11-2012
Thanks. I must have the lines on separate lines (the lines are long and are written into an HTML table for readability).
# 6  
Old 01-11-2012
Quote:
Originally Posted by mmr11408
The string "diff" does exist in both files (I created the files to show an example).
If the files are identical, then why is any difference reported?
# 7  
Old 01-11-2012
The sample files that I created are not identical. One has extra periods (.) at the end.
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