Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

diff .. or better way to compare files

Status
Not open for further replies.

RFC1795

IS-IT--Management
Feb 13, 2003
76
US
Hi,

I need to perform checks against two files. I've searched the boards but have not found a simple solution.

Ideally I need to compare the files and have the output show whats missing or extra in one and visa versa. I thought this would be nice and simple using diff , but its proving complicated. (Its also been a long week and the brain is shutting down) ;-)

Sample of problem:
One file, the static source file(FILE_A) contains the following:
access-list 199 permit eigrp any any
access-list 199 permit ospf any any
access-list 199 permit tcp any any eq bgp
access-list 199 permit tcp any eq bgp any
access-list 199 permit udp any any eq rip
access-list 199 permit udp any eq rip any
access-list 199 permit udp any eq rip any eq rip

The other file (FILE_B) contains :
access-list 199 permit 9 any any
access-list 199 permit eigrp any any
access-list 199 permit tcp any any eq bgp
access-list 199 permit tcp any eq bgp any
access-list 199 permit ospf any any
access-list 199 permit udp any eq rip any eq rip

If I do a simple diff on it I get this output:
1d0
< access-list 199 permit 9 any any
2a2
> access-list 199 permit ospf any any
5c5,6
< access-list 199 permit ospf any any
---
> access-list 199 permit udp any any eq rip
> access-list 199 permit udp any eq rip any

The problem is clear above.. sorting the files 1st will help resolve some of them but could still cause problems further on.

Is there a simpler way to get to my objective?

Thanks .. TJ

 
You can try to sort the two files and then play with the comm command.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
cat file1 file2 > newfile
a=`wc -l file1|awk '{print $1}'`
b=`wc -l file2|awk '{print $1}'`
uniq newfile > file3
c=`wc -l file3|awk '{print $1}'`

d=`expr $a + $b`

if ( $c = $d );then
echo &quot;No Diff&quot;
else
echo &quot;Found Diff&quot;
fi

Not tested, not perfect


--
| Mike Nixon
| Unix Admin
|
----------------------------
 
If you just want to test if two files are different or identical, use 'cmp' command

Jean Pierre.
 
>The problem is clear above.. sorting the files 1st will help resolve some of them but could still cause problems further on.

??? The only "problem" I see is that it is flagging those lines that are common but in different places in the file, and sort would seem to TOTALLY solve that. So what "problems further on" do you mean? If it's a question of removing the extra verbiage, just pipe it into something to select the lines with the <> chars. What am I missing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top