Better version of diff?

Dan Nelson dnelson at allantgroup.com
Mon May 18 04:57:35 UTC 2009


In the last episode (May 17), Kelly Jones said:
> I often need to compare two Perl files sans comments. This mostly works:
> 
> egrep -v '^#' file1.pl > file1.tmp
> egrep -v '^#' file2.pl > file2.tmp
> diff -B file1.tmp file2.tmp

Take a look at the -I option to diff.  It lets you ignore lines matching a
specified regex.

> (yes, it breaks for perldoc style comments, comments on lines w/ code,
> # characters inside HERE docs, and probably other cases-- just an
> approximation)
> 
> I also often need to see if two files contain the same lines, minus
> comments and allow duplicates. This mostly works:
> 
> egrep -v '^#' file1.txt | sort | uniq > file1.tmp
> egrep -v '^#' file2.txt | sort | uniq > file2.tmp
> diff -B file1.tmp file2.tmp;: comm would also work here

No suggestions here.  Sorting a file is not something diff should do imho.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list