Tag Info

Hot answers tagged

30

Try to use - to represent the standard input. ssh user@remote-host "cat path/file.name" | diff path/file.name -


26

To understand the report, remember that diff is prescriptive, describing what changes need to be made to the first file (file1) to make it the same as the second file (file2). Specifically, the d in 1d0 means delete and the a in 2a2 means add. Thus: 1d0 means line 1 must be deleted in file1 (apples). 0 in 1d0 means line 0 is where they would have ...


25

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


19

Here's one workaround: diff seems to accept <(expr) as arguemnts: diff <(ssh \"cat path/file.name/") <(cat path/file.name)


18

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


17

Open the side by side view: Ctrl+w v Change between them: Ctrl+w h or l Checkout the vimdiff command, part of the vim package, if you want a diff-like view..


15

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


15

sort can be used to get the files into the same order so diff can compare them and identify the differences. If you have process substitution, you can use that and avoid creating new sorted files. diff <(sort file1) <(sort file2)


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


14

There's wdiff, the word-diff for that. On desktop, meld can highlight the differences within a line for you.


13

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

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


12

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


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

There are a number of tools that are usable: meld kompare -- diff file viewer kdiff3 -- file difference viewer Diffuse -- file difference viewer Do you have two files and want to view their differences? Use a "file difference viewer". Do you have a diff file and want to look at it in an easy-to-read display? Use a "diff file viewer".


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

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


11

Consider these files: file1: # cat file1 apples pears oranges peaches file2: # cat file2 oranges apples peaches ananas banana How diff works, given it is order-based: diff reads the first block of lines of file1 and file2, and tries to find equal lines: file1 file2 differences on left (<) or right side (>) apples ...


11

Git uses isatty() to check whether stdout is a tty: this is used to see if a pager must be used (pager.c) as well as colors (color.c).


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

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


10

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


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


10

ssh user@remote_host "cat remote_file.txt" | diff - local_file.txt Source


9

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


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

Don't you want the other way around? diff -Nub . /current-files | patch -b



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