• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

what is the same (UNdiff)

in the unix in order to find out what is different between two files we use the "diff <file1> <file2> > <output file>
(optional the grep) ,but i have the oposite problem ,i want to find out what is the same in two files (there must be nothing the same) ,and they are huge files so the diff will give me whole pages of text that will not help me ,so what i need is to know the command or script on how to know what is the same between two files ,can somebody help me on this please
0
doron123
Asked:
doron123
  • 7
  • 6
  • 3
  • +1
1 Solution
 
ozoCommented:
sort file1 > file1.sort
sort file2 | comm -12 - file2.sort

If there is also nothing repeated within each file,
you could also check
sort file1 file2 | sort -uc
0
 
doron123Author Commented:
thank you ,i'll explain further more ,I need to know if names within the file are the same (there must be NONE!!) ,the comm can do only for a line ,is there anything like the comm but can spot names?
0
 
ozoCommented:
If names are separated by spaces
tr -s ' ' '\n' < file1 | sort > names.sort
etc.
Or if you can explain how to recognise a name, a simple Perl command could do it.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
doron123Author Commented:
i have two files to compare ,in the tr command you wrote i can use only one ... how can i do that ,could you please re exlain the command .
thanks
0
 
ozoCommented:
tr -s ' ' '\n' < file1 | sort > names1.sort
tr -s ' ' '\n' < file2 | sort | comm -12 - names1.sort
0
 
ahoffmannCommented:
cat file1 file2 | tr -s ' ' '\012' | sort | uniq -d
0
 
ozoCommented:
You can use that if you don't mind catching repeats a single file, (as I said)
0
 
braveheartCommented:
I like sdiff which prints the files side by side, indicating
which lines are the same, different or which have been added
to one or the other file. For example, if one file contains:
x
a
b
c
d
and the other file contains:
y
a
d
c
sdiff gives the following output:
x    |    y
a         a
b    <
c    <
d         d
     >    c

| means that the line has changed
  means no change
< means added to the first file w.r.t the second file
> means added to the second file w.r.t. the first.


0
 
doron123Author Commented:
thank you ,but in this case i'll see only the diffs that are place oriented!!!.
my problem is i work with asics ,and i get huge files containing not all the times at the same location the names ,and most of the times i get instance names in the middle of the line that are identical ,(but the rest of the line is not identical).
if you could help me so do that .
exept the sort first and than undiff ....

thanks ahead :
===============
Doron Amedey

0
 
ozoCommented:
What is a name?  How do you know when a name in the middle of a line?
If names are delimited by spaces, the tr | sort solution should work.
0
 
doron123Author Commented:
the syntax is <name> .<module>/<instance> <names>
and if i must track down instances than here is the problem.
do you have any solution for this problem here.

0
 
braveheartCommented:
Oops, the formatting went awry. The output should be
   x   |   y
   a       a
   b   <
   c   <
   d       d
       >   c



0
 
braveheartCommented:
Are you saying that your file contains lots of different records
on the same line? If so, you must first separate your records.
Perhaps an awk/nawk/gawk solution would be more appropriate
where you can specify your own field separators. Beware that if
you use large files you should use either nawk or gawk because
awk has poor garbage collection on some systems.
0
 
ahoffmannCommented:
I understand your problem as follows:
   you have a diff output od 2 files and you want remove
   the diffs of lines which are identical in  <unstance>
   means:
       <  name1 .module/instance name1
       --
       <  name2 .module/instance name1
   should be removed
If this is what you wnat, a perl filter could do it. Give ozo a chance ;-)
0
 
doron123Author Commented:
this is what i need but 2 things :
1.) the mudule is not the same in most cases!!
2.) the name1 is not the same all ways!!
3.) one of those 3 elements is the same in some lines

and i don't want to delete them ,but i need to change one of the identical names in the netlist to other name.
so all i need to do first is to know which lines in the first file has some equivalent value as the x line (!! important) on file two.

help me and i'll reward you !!!>
thanks
0
 
doron123Author Commented:
where can i find those awk/nawk/gawk programs?

0
 
doron123Author Commented:
where can i find those awk/nawk/gawk programs?

0
 
ozoCommented:
Given the syntax <name> .<module>/<instance> <names>
this should extract the names

awk '{$2 = ""; OFS="\n"; print $0}' <file | grep . | sort
0
 
ahoffmannCommented:
> where can i find those awk/nawk/gawk programs?

awk is usually part of any UNIX: /usr/bin/awk
Some UNIXs have nawk also or instead (HP-UX): /usr/bin/nawk
gawk is GNU's version of awk: ftp://ftp.gnu.org/pub/gnu
  (most UNIXs deliver it too; IRIX, HP-UX)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now