There's a tool call DHEX which may do the job.
And there's another tool called VBinDiff
For a strictly command-line approach, try JDIFF
see also :
cmp - diff3 - sdiff - patch
diff [OPTION]... FILES
Step 2
You should probably take a look at the rsync-related tools:
rdiff and rdiff-backup. The
rdiff
command lets you produce a patch file and
apply it to some other file.
The rdiff-backup
command uses this approach to deal
with entire directories, but I'm guessing you're working with
single-file disk images, so rdiff
will be the one to
use.
I use Beyond Compare to compare all types of text based files. They produce versions for Windows and Linux.
Found a solution - the cmp tool which comes with most Linux flavours.
I found this link
diff -H might help, or you can try installing the textproc/2bsd-diff port which apparently doesn't try to load the files into RAM, so it can work on large files more easily.
I'm not sure if you tried those two options or if they might work for you. Good luck.
One way to do this is to do
diff dir1 dir1| grep "diff "
It will still do a line-by-line comparison, but each file comparison begins with "diff dir1/file dir2/file", so grepping "diff " will show only those lines ( i.e. the files that are different ).
To compare files side-by-side, my favorite tool is Notepad++.
After installing it, on the toolbar click Plugins>Plugin Manager>Available, and check Compare and Install.
After restarting Notepad++, open up the two files (they will open in different tabs), and in the toolbar go to Plugins>Compare>Compare.
There are multiple tweaks you can do, but comparing files looks something like this:
where white text is unchanged, red is removed, green is added, and the sidebar shows an overview of those changes in the two files.
Ah just found out about vimdiff. It pretty much does what I was looking for. here's a quick guide
Not sure diff
alone can do it but you can always use
the power of other GNU utilities to help you.
diff -u diffa.txt diffb.txt | grep '^-[^-]' | sed 's/^-//'
It does the diff, then selects only the lines that begins with
'-' - those are changed and have values from diffa.txt file, then
sed
just remove those '-' signs.
Edit: After few experiments with
diff
, looks like the below command produces what you
want:
diff --changed-group-format='%<' --unchanged-group-format='' diffa.txt diffb.txt
If your looking for command line diff would work wouldn't it? For graphical and not free I like Beyond Compare
Two possible causes:
If this is a one-time problem, I'd create copies of the files
with \n
characters inserted every 50 characters,
then diff those copies. (I chose 50 because it makes the math
easy going from differing line number to byte offset in the
original files but might adjust that up/down based on what I
found.)
When using rsync
, It seems that the -c
(--checksum
) option does not override the
-t
(--times
) option within
-a
(--archive
), which uses
-rlptgoD
, and thus it will still look at file
modification times.
One possible solution is to use: -rlpgoDc
rather
than -a
. The command would look like this:
cd Package_1.2
rsync -rlpgoDc --compare-dest=../Package_1.1 . ../changed_files/
find -depth ../changed_files -type d -empty -delete
This may not be the most elegant solution, perhaps someone has a
better idea of how rsync
can do the whole job by
itself.
Here you go:
diff <(head -n 1 file1) <(head -n 1 file2)
(this would return nothing what-so-ever).
diff <(head -n 2 file1) <(head -n 2 file2)
Returns:
2c2
< 1
---
> 3
You could incorporate that into a script to do the things you mention.
#!/bin/bash
fileOne=${1}
fileTwo=${2}
numLines=${3:-"1"}
diff <(head -n ${numLines} ${fileOne}) <(head -n ${numLines} ${fileTwo})
To use that, just make the script executable with chmod +x
nameofscript.sh
and then to execute,
./nameofscript.sh ~/file1 ~/Docs/file2
That leaves
the default # of lines at 1, if you want more append a number to
the end of that command.
(Or you could do switches in your script with -f1 file1 -f2 file2 -n 1, but I don't recall of the top of my head the case statement for that).
head
returns from the beginning the # of lines as
suggested by -n
. If you were to want to do reverse,
it would be tail -n ${numLines}
(tail does from the
end back the number of lines).
Compare FILES line by line.
Mandatory
arguments to long options are mandatory for short options
too.
--normal
output a normal diff (the default)
-q, --brief
report only when files differ
-s, --report-identical-files
report when two files are the same
-c, -C NUM, --context[=NUM]
output NUM (default 3) lines of copied context
-u, -U NUM, --unified[=NUM]
output NUM (default 3) lines of unified context
-e, --ed
output an ed script
-n, --rcs
output an RCS format diff
-y, --side-by-side
output in two columns
-W, --width=NUM
output at most NUM (default 130) print columns
--left-column
output only the left column of common lines
--suppress-common-lines
do not output common lines
-p, --show-c-function
show which C function each change is in
-F, --show-function-line=RE
show the most recent line matching RE
--label LABEL
use LABEL instead of file name (can be repeated)
-t, --expand-tabs
expand tabs to spaces in output
-T, --initial-tab
make tabs line up by prepending a tab
--tabsize=NUM
tab stops every NUM (default 8) print columns
--suppress-blank-empty
suppress space or tab before empty output lines
-l, --paginate
pass output through ’pr’ to paginate it
-r, --recursive
recursively compare any subdirectories found
-N, --new-file
treat absent files as empty
--unidirectional-new-file
treat absent first files as empty
--ignore-file-name-case
ignore case when comparing file names
--no-ignore-file-name-case
consider case when comparing file names
-x, --exclude=PAT
exclude files that match PAT
-X, --exclude-from=FILE
exclude files that match any pattern in FILE
-S, --starting-file=FILE
start with FILE when comparing directories
--from-file=FILE1
compare FILE1 to all operands; FILE1 can be a directory
--to-file=FILE2
compare all operands to FILE2; FILE2 can be a directory
-i, --ignore-case
ignore case differences in file contents
-E, --ignore-tab-expansion
ignore changes due to tab expansion
-b, --ignore-space-change
ignore changes in the amount of white space
-w, --ignore-all-space
ignore all white space
-B, --ignore-blank-lines
ignore changes whose lines are all blank
-I, --ignore-matching-lines=RE
ignore changes whose lines all match RE
-a, --text
treat all files as text
--strip-trailing-cr
strip trailing carriage return on input
-D, --ifdef=NAME
output merged file with ’#ifdef NAME’ diffs
--GTYPE-group-format=GFMT
format GTYPE input groups with GFMT
--line-format=LFMT
format all input lines with LFMT
--LTYPE-line-format=LFMT
format LTYPE input lines with LFMT
These format options provide fine-grained control over the output
of diff, generalizing -D/--ifdef.
LTYPE is ’old’, ’new’, or ’unchanged’.
GTYPE is LTYPE or ’changed’.
GFMT (only) may contain:
%[-][WIDTH][.[PREC]]{doxX}LETTER
printf-style spec for LETTER
LETTERs are as follows for new group, lower case for old group:
%(A=B?T:E)
if A equals B then T else E
LFMT (only) may contain:
%[-][WIDTH][.[PREC]]{doxX}n
printf-style spec for input line number
Both GFMT and LFMT may contain:
%c’\OOO’
the character with octal code OOO
-d, --minimal
try hard to find a smaller set of changes
--horizon-lines=NUM
keep NUM lines of the common prefix and suffix
--speed-large-files
assume large files and many scattered small changes
-v, --version
output version information and exit
FILES are ’FILE1 FILE2’ or ’DIR1 DIR2’ or ’DIR FILE...’ or ’FILE... DIR’. If --from-file or --to-file is given, there are no restrictions on FILE(s). If a FILE is ’-’, read standard input. Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.
Copyright © 2011 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
Report bugs to: bug-diffutils[:at:]gnu[:dot:]org
GNU diffutils home page:
<http://www.gnu.org/software/diffutils/>
General help using GNU software:
<http://www.gnu.org/gethelp/>
wdiff, cmp , diff3 , sdiff , patch
The full documentation for diff is maintained as a Texinfo manual. If the info and diff programs are properly installed at your site, the command
info diff
should give you access to the complete manual.
Written by Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, and Len Tower.