Tag Info

Hot answers tagged

14

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


14

diff expect 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 bash, you can fool diff with the command diff <(awk '{print $3}' f1.txt | sort -u) <(awk '{print $2}' f2.txt | sort -u)


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


11

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


10

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.


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

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

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


9

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


9

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


8

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


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

$ 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)'


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

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


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

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


6

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


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


5

To see a listing, here are two variants, one that recurses into subdirectories and one that doesn't. All use syntax specific to bash, ksh and zsh. comm -3 <(cd source && find -type f | sed 's/\.[^.]*$//' | sort) \ <(cd dest && find -type f | sed 's/\.[^.]*$//' | sort) comm -3 <(cd source && for x in *; do printf ...


5

The command rsync --only-write-batch=FILE $other_options ORIGINAL_AND_MY_CHANGES/ ORIGINAL/ would produce a batch FILE containing the changes required (without modifying anything). The patch could be applied on another site, where you take the batch FILE, with rsync --read-batch=FILE ORIGINAL/


5

Wild guess: your script is operating under set -e (synonym: set -o errexit), which causes the shell to exit if any commands returns a nonzero status (conventionally indicating failure). If so, it will exit if diff finds any difference, because diff returns the status 1 if it finds differences. If this is the problem, then change that line to diff -r ...


5

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)


4

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


4

I mention this one only because I want someone to write a GNU version... Brenda S. Baker, of Bell Labs, wrote a system called dup that did what you want to do and more. You could use dup to compare two C-language systems, and find code that's kind-of-duplicated: a function copied and variables renamed or some such minor changes. The whole SCOg Fiasco ...


4

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.


4

To pass a numeric argument to a command, enter the argument first. For example, Escape 3 Left moves 3 characters left. So type ESC 3 ESC x compare-windows RET or M-3 M-x compare-windows RET. The most frequently used commands to compare two files are those of ediff. You can invoke them from the “Tools > Compare (Ediff)” menu. There is a command called ...


4

Made a script for this which keeps the line sequence intact. Here's an annotated version of the important lines: # Strip all context lines diff_lines="$(grep '^[><+-] ' | sed 's/^+/>/;s/^-/</')" || exit 0 # For each line, count the number of lines with the same content in the # "left" and "right" diffs. If the numbers are not the same, then the ...


4

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



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