Problem in using diff


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in using diff
# 1  
Old 04-18-2008
CPU & Memory Problem in using diff

Hi,

When i use diff command, i get the output like this

Code:
2c2
< Table Name: AAA Row Count:96 SUM(F1):  3739 MAX(F1):77 MIN(F1):  0 AVG(F1): 38.9479167 LENGTH(LINE): 2260
---
> Table Name: AAA Row Count:96 SUM(F1):  4009 MAX(F1):77 MIN(F1):  0 AVG(F1): 40.9479167 LENGTH(LINE): 2260
4a5,10
>

I need an output without the unnecessary symbols. That is my ouput should like this.

Code:
Table Name: AAA Row Count:96 SUM(F1):  3739 MAX(F1):77 MIN(F1):  0 AVG(F1): 38.9479167 LENGTH(LINE): 2260
Table Name: AAA Row Count:96 SUM(F1):  4009 MAX(F1):77 MIN(F1):  0 AVG(F1): 40.9479167 LENGTH(LINE): 2260

What could be done to get an output like this? Can anyone help?Smilie

Last edited by Yogesh Sawant; 04-19-2008 at 06:22 AM.. Reason: added code tags
# 2  
Old 04-18-2008
Depending on the implementation of diff you're using, you can have "--exclude=pattern" where pattern may be characters. Look at the man pages and you'll find the answer.
# 3  
Old 04-18-2008
Quote:
Originally Posted by ragavhere
Hi,

When i use diff command, i get the output like this

2c2
< Table Name: AAA Row Count:96 SUM(F1): 3739 MAX(F1):77 MIN(F1): 0 AVG(F1): 38.9479167 LENGTH(LINE): 2260
---
> Table Name: AAA Row Count:96 SUM(F1): 4009 MAX(F1):77 MIN(F1): 0 AVG(F1): 40.9479167 LENGTH(LINE): 2260
4a5,10
>

I need an output without the unnecessary symbols. That is my ouput should like this.

Table Name: AAA Row Count:96 SUM(F1): 3739 MAX(F1):77 MIN(F1): 0 AVG(F1): 38.9479167 LENGTH(LINE): 2260
Table Name: AAA Row Count:96 SUM(F1): 4009 MAX(F1):77 MIN(F1): 0 AVG(F1): 40.9479167 LENGTH(LINE): 2260

What could be done to get an output like this? Can anyone help?Smilie
I usually use sdiff - it still has symbols in it, but I find the output to be a lot cleaner, and it shows (in full, and not a bunch of broken up lines) both of the files you're comparing side by side.
# 4  
Old 04-18-2008
You may also want to try the cmp command - stands for compare.

It produced output in three columns: Lines unique to file1, unique to file2 and common. Flags can be used to eliminate columns.

If you select the flags to eliminate column 1 and 2, all you're left with is the common lines, without any additional characters, lines, or anything. I think that will give you the output you're asking for.
# 5  
Old 04-19-2008
CPU & Memory Prob using diff

Hi,

I need to display only the lines which mismatch from both the files.So i cant use cmp.It will only give me lines unique to either of the files.

So its better to use diff and remove the unnecessary characters and symbols.

How can i remove the "<" and "---" and "2c2","4a5,10". These numbers can go upto 1000 or more. Is there a generic way to remove these from the output obtained by using diff command?
# 6  
Old 04-19-2008
I'm not sure why you can't use cmp. Lines which differ are, by definition, unique.

You can create a simple sed script to remove the diff markup, but I'd still like you to give some more thought to using cmp after all. To me, it sounds like the right tool for this job.

Code:
sed -e '/^-/d' -e '/^[1-9]/d' -e 's/^[<>] //' difffile

The character ^ indicates start of line in a regular expression. Any line with a dash at start of line is deleted. Any line with a non-zero number at start of line is deleted. On remaining lines, a wedge (either way) followed by a space at start of line is replaced with nothing.
# 7  
Old 04-19-2008
Oopsie, thinko, I meant comm of course. But I presume that's what you other guys have been meaning all along as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with diff

I am using the diff command, but i cant figure out why it is displaying these strange numbers and letters diff spellExample spellExample.bak 1c1 < I went to a garden party --- > I went to a gadren party 3c3 < bunch of my old friends did something --- > bnuch of my old freinds did... (2 Replies)
Discussion started by: football12345
2 Replies

2. Shell Programming and Scripting

diff problem

Hi, I need to get only different rows from comparing two files , i donot need the place of row or any other error comments , just my data , Can anyone help me please? example: $Diff -b reham.txt reham1.txt 7a8(DON'T NEED IT) > hany 4/4/1989 $100,000 \ No newline at end... (9 Replies)
Discussion started by: Reham.Donia
9 Replies

3. Shell Programming and Scripting

Problem in Diff command...

Hi All, I havae 2 files like this File1.dat.tar.gz--- has +667866066123|20110506 +667866066866|20110405 File2.dat.tar.gz -----contains +447866066123|20110505 +447866066866|20110405 If I give Gzcat File1.dat.tar.gz | cut –d “|” –f 1 > out1.dat Gzcat File2.dat.tar.gz| cut –d... (4 Replies)
Discussion started by: suresh01_apk
4 Replies

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

5. UNIX for Dummies Questions & Answers

Problem with diff command

Hello Guys, I am a newbie to Unix. I was going through the diff command with example like this, $ cat 1 1 2 4 0 8 9 $ cat 2 1 0 3 2 8 My output is like this: (1 Reply)
Discussion started by: mahesh_raghu
1 Replies

6. UNIX for Dummies Questions & Answers

Not sure how to use diff and comm for my problem

Hello, Apologies if this question has been repeated before, but I am getting myself confused even more as I scan the posts! I have two files, file1 is a column: 1dlwa_ 1s69a_ 1idra_ 1ngka_ And file2 has three columns (columns seperated by tabs): 1dlw a_ A 1uvy a_ A 1dly a_ A 1uvx... (1 Reply)
Discussion started by: InfoSeeker
1 Replies

7. UNIX for Dummies Questions & Answers

Problem with diff command

I am trying to do a diff between two files using "diff" command.I dont need my output to be printed using extra symbols ">" and "<" as we usually see for the diff command. Even to excude these characters in each line of the output, my diff output has inturn many symbols ">" and "<". Please help.... (2 Replies)
Discussion started by: pharitha
2 Replies

8. UNIX for Advanced & Expert Users

Problem using diff command in unix

Hi, I am trying to do a diff between two files using "diff" command.I dont need my output to be printed using extra symbols ">" and "<" as we usually see for the diff command. Even to excude these characters in each line of the output, my diff output has inturn many symbols ">" and "<". ... (1 Reply)
Discussion started by: pharitha
1 Replies

9. Shell Programming and Scripting

Diff command problem

Folks, I am Diff'ing 2 identical files..and the result is, it shows all the lines from 2 files (saying nothing is being matched). If I copy the content from 1 of the file and paste in a newly created file and then do the diff, it equals. 2 files are xml files. I've tried many... (4 Replies)
Discussion started by: gvsreddy_539
4 Replies

10. UNIX for Advanced & Expert Users

problem with diff and tcl scripts freaking out unix

running solaris 2.5.1 on a sparc5, with less than 12 users runnign compilers, gui's, really not a heavy load on it however, sometimes, not always, when users run diff, or sdiff or a .tcl script, the computer locks up. One time right before everything froze, I noticed in top, that the sdiff process... (2 Replies)
Discussion started by: kymberm
2 Replies
Login or Register to Ask a Question