Tag Info

Hot answers tagged

20

do (diff obtain) and dp (diff put) is what you need. Here is a small list of other helpful commands in this context. ]c - advance to the next block with differences [c - reverse search for the previous block with differences do (diff obtain) - bring changes from the other file to the current file dp (diff put) - send changes ...


16

The most obvious answer is just to use the diff command and it is probably a good idea to add the --speed-large-files parameter to it. diff --speed-large-files a.file b.file You mention unsorted files so maybe you need to sort the files first sort a.file > a.file.sorted sort b.file > b.file.sorted diff --speed-large-files a.file.sorted ...


15

diff expects the names of two files, so you should put the two output on two files, then compare them: awk '{print $3}' f1.txt | sort -u > out1 awk '{print $2}' f2.txt | sort -u > out2 diff out1 out2 or, using ksh93, bash or zsh, you can fool diff with the command: diff <(awk '{print $3}' f1.txt | sort -u) <(awk '{print $2}' f2.txt | sort -u) ...


13

According to Gilles, the -I option only ignores a line if nothing else inside that set matches except for the match of -I. I didn't fully get it until I tested it. The Test Three files are involved in my test (take the indented code, ignore File test*; I did it this way to prevent formatting making it less readable): File test1: text File test2: ...


12

How about using diff, even though you don't want a diff? Try this: diff --unchanged-group-format='@@ %dn,%df %<' --old-group-format='' --new-group-format='' \ --changed-group-format='' a.txt b.txt Here is what I get with your sample data: $ cat a.txt Foo Bar X Hello World 42 $ cat b.txt Foo Baz Hello World 23 $ diff ...


12

Install an utility like Meld (there are other utilities for doing this, too, but I like Meld since it doesn't have KDE/GNOME dependencies) and use it for visually diffing/merging the files. Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and ...


12

diff -e bigger smaller will do the trick, but requires some interpretation, as the output is a "valid ed script". I made two files, "bigger" and "smaller", where the contents of "smaller" is identical to lines 5 through 9 of "bigger" doing `diff -e bigger smaller" got me: % diff -e bigger smaller 10,15d 1,4d Which means "delete lines 10 through 15 of ...


11

Two backup tools that can store binary diffs are rdiff-backup and duplicity. Both are based on librsync, but above that they behave quite differently. Rdiff-backup stores the latest copy and reverse diffs, while duplicity stores traditional incremental diffs. The two tools also offer a different set of peripheral features.


11

There's no need to put the output of diff in a variable, since you can tell whether files differ based on the exit status of diff, e.g. if diff -q file1 file2 >/dev/null 2>&1; then # files are equal else # files differ, or an error occurred fi diff returns success (0) if the files do not differ. Adjust the logic as necessary. ...


10

Lately I've been trying out storing database dumps in git. This may get impractical if your database dumps are really large, but it's worked for me for smallish databases (Wordpress sites and the like). My backup script is roughly: cd /where/I/keep/backups && \ mysqldump > backup.sql && \ git commit -q -m "db dump `date '+%F-%T'`" ...


10

jw013 is right, you don't need this line anyway. But to answer the actual question, you have left out quotation marks around the variable that you passed into test (otherwise known as [). This means if your variable is empty, it will be as if you had no arguments (eg [ -n ]), and if your variable contains spaces, it will be as if you passed multiple ...


10

Yes, it is possible. When using these options, the default is just to print out every line. This is very verbose, and not what you want. diff --unchanged-line-format="" will eliminate lines that are unchanged, so now only the old and new lines are produced. diff --unchanged-line-format="" --new-line-format=":%dn: %L" will now show the new lines ...


10

Might the differences be caused by DOS vs. UNIX line endings, or something similar? What if you hexdump them? This might show differences more obviously, eg: hexdump -C file1 > file1.hex hexdump -C file2 > file2.hex diff file1.hex file2.hex


10

I would certainly use vimdiff, simply because vim is my default editor. Check if your editor has a diff option first, as it makes things easier. There are many graphical tools, the most user-friendly being Meld (as suggested by Renan). Also consider using latexdiff to see the differences in a nice pdf format. latexdiff paper.tex ...


9

$ alias diff='diff -W $(( $(tput cols) - 2 ))' ought to do it. You'll want to add it to ~/.bashrc as well. The - 2 is mainly paranoia, in case something (embedded double-width Unicode?) expands enough to make the line wrap; if you want, you can just use $ alias diff='diff -W $(tput cols)'


9

It's called "paging output" or (somewhat erroneously) "pagination" … … and man does it by invoking your preferred pager shell command, named by your PAGER environment variable, upon the output of whatever pipeline was used to generate the output form of the manual page. It falls back to a default if you haven't specified a pager command. On ...


9

One approach could be to compute the Levenshtein distance. Here using the Text::LevenshteinXS perl module: distance() { perl -MText::LevenshteinXS -le 'print distance(@ARGV)' "$@" } Then: $ distance foo foo 0 $ distance black blink 2 $ distance "$(cat /etc/passwd)" "$(tr a b < /etc/passwd)" 177 Here's a line-based implementation of the ...


8

You can also open vim in split-screen mode, with the -O option:- vim -O file1 [file2 ...] To then turn on diff mode, you need to run the :diffthis command in each pane. Another use-case scenario, is if you've already got one file open in vim, and you want to open and compare it against another. Then you can use the following vim commands:- :vs otherfile ...


7

I've used vimdiff for this. Here's a screenshot (not mine) showing minor one or two character differences that stands out pretty well. A quick tutorial too.


7

The simple answer is: "compare the sorted version of both files". In bash: diff <(sort file1) <(sort file2) Obviously, this does not mean the two files have the same semantic as source files of a programming language (supposing are both syntactically correct).


7

You can use the diff toool: see the options -q and -r -q --brief Output only whether files differ. -r --recursive Recursively compare any subdirectories found. Example: diff -qr dir1 dir2


7

In no particular sequence: meld is a very nice diff program which does very nice diffs and three-way merges. git config --global merge.conflictstyle diff3 gets you three-way merge output for use with tools like meld. wdiff does word diffs, very nice if colored: wdiff -w "$(tput bold;tput setaf 1)" -x "$(tput sgr0)" -y "$(tput bold;tput setaf 2)" -z "$(tput ...


7

The answer to this question is probably what you want. It links to these tools, which do the conversion you're looking for: Perl package HTML::FromANSI aha, a C-language program (github repo)


7

Either use diff -u file1 file2 or git diff branch/commit1 branch/commit2 More on git diff at https://www.kernel.org/pub/software/scm/git/docs/git-diff.html I am not aware of any --git option however for diff and the man page doesn't show it.


6

Given bash, this might be easiest as $ comm <(ls -a dir1) <(ls -a dir2) The <(command) expression runs command over a pipe and substitutes a /dev/fd reference: mress:10018 Z$ echo <(ls) /dev/fd/11 So the command above runs ls -a on each directory and feeds their outputs as file arguments to comm, which outputs up to 3 columns, tab-indented: ...


6

The program auxiliary that man and git diff invoke is called a pager. On modern systems, the default pager is called less. Several decades ago, the first pager was more, so called because it displayed one page then waited for you to press a key to see “more”. Then came less, which also let you go back (to see less, so to speak), confirming the saying that ...


6

With GNU diff, pass one of the files as an argument to --from-file and any number of others as operand: $ diff -q --from-file file1 file2 file3 file4; echo $? 0 $ echo >>file3 $ diff -q --from-file file1 file2 file3 file4; echo $? Files file1 and file3 differ 1


6

A floppy device file is a file. Any command that reads files will work on it. cmp /dev/fd0 image.fat Pass the -l option if you want a list of all differing bytes; for human consumption, this is mostly useful in the form cmp -l /dev/fd0 image.fat | wc -l to know how many bytes differ. Run cmp -s /dev/fd0 image.fat if you don't want any output, just a ...


6

bdiff appears to be available on Linux (at least as part of the Heirloom Toolchest). diff I would probably just use regular old diff with this switch however: diff --speed-large-files bigfileA bigfileB Why it doesn't work? See comment by @EvanTeitelman, --speed-large-files doesn't affect how files are loaded into memory. Can be demonstrated/confirmed ...


6

Make assumes that an exit code of 0 means success, anything else means failure. This is the standard convention used by almost all command-line tools. Unfortunately, diff is not one of those. Checking the GNU diff info page, and also the Single Unix Specification "diff" entry, 0 means no differences found, 1 means differences found, and ≥2 means error. You ...



Only top voted, non community-wiki answers of a minimum length are eligible