Link to home
Start Free TrialLog in
Avatar of doron123
doron123

asked on

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
Avatar of ozo
ozo
Flag of United States of America image

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
Avatar of doron123
doron123

ASKER

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?
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.
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
tr -s ' ' '\n' < file1 | sort > names1.sort
tr -s ' ' '\n' < file2 | sort | comm -12 - names1.sort
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use that if you don't mind catching repeats a single file, (as I said)
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.


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

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

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



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.
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 ;-)
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
where can i find those awk/nawk/gawk programs?

where can i find those awk/nawk/gawk programs?

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

awk '{$2 = ""; OFS="\n"; print $0}' <file | grep . | sort
> 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)