Tag Info

New answers tagged

6

The standard (old) output format will display the difference between the files without surrounding text with areas where the files differ. For example: 1d0 < (delete) means the apples needs to be removed from the 1st line of file1, and 2a2 > (append) means the apples needs to be added into file2 on the 2nd line, so both files can be matched. ...


7

There they are: $ diff file1 file2 1d0 < apples 2a2 > apples $ diff file2 file1 1d0 < oranges 2a2 > oranges


10

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


25

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


3

Maybe this is not helpful in your exact case, but I often simply use sum -r on each machine, and manually compare the checksums. That allows for comparisons of files even when they are not reachable via an ssh connection. Of course, all it answers is "are they identical", but often that is sufficient for my needs. It also makes it easy to verify that a ...


6

Try: diff local_file <(ssh user@server 'cat remote_file') or using vimdiff: vimdiff local_file scp://server//path/to/remote_file


10

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


6

The less command by itself cannot do any diff'ing. You can use the diff -y command to show the diff of 2 files side-by-side and then pipe that into less however. Method #1 - using diff + less This will create 2 sample files. $ seq 100 > 1.txt $ seq 10 100 > 2.txt Now diff the 2 files: $ diff -y 1.txt 2.txt | less 1 ...


2

I am not sure if it is possible using less command. However, it is possible using the below command. From here, pr -m -t one.txt two.txt One more option that is useful though doesn't display side by side is, tail -f file1 -f file2


0

You have to add one more option : grep -vf file1 file2


0

This will be very slow for large files, but you could do $ while read a rest; do grep -w $a file2; done < file1 aaa a m bbb m a ccc m m A faster way, in Perl: $ cat file1 | perl -lane '$k{$F[0]}=$_; END{ open(A,"file1"); while(<A>){/^(.+?)\s/; print $k{$1}} }' file2 aaa a m bbb m ...


4

Try this: $ awk 'FNR==NR{a[$1]=$0;next} {print a[$1]}' file2 file1


1

I think this ought to do what you need: diff -r -U0 a/ b/ | awk '/^+++ / {filename=$2; next} /^@@ / {split($3,a,","); line=substr(a[1],2)} /^+/ {text=substr($0,2); print filename ":" line ":" text; line++}' Basically, it does an ordinary recursive diff, and then discards the bit you don't want. awk is cool for stuff like this. diff -U0 gives output like ...



Top 50 recent answers are included