GNU bug report logs - #16618
How to show the diff command when there is a difference when comparing two files?

Previous Next

Package: diffutils;

Reported by: Peng Yu <pengyu.ut <at> gmail.com>

Date: Sat, 1 Feb 2014 19:28:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Peng Yu <pengyu.ut <at> gmail.com>
Subject: bug#16618: closed (Re: How to show the diff command when there is
 a difference when comparing two files?)
Date: Sun, 30 Mar 2014 05:23:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#16618: How to show the diff command when there is a difference when comparing two files?

which was filed against the diffutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 16618 <at> debbugs.gnu.org.

-- 
16618: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16618
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: 16618-done <at> debbugs.gnu.org
Subject: Re: How to show the diff command when there is a difference when
 comparing two files?
Date: Sat, 29 Mar 2014 22:22:40 -0700
> I'm wondering if I just compare two files, it is
> possible to print the diff command if there is a difference between
> the two files?

Not in diff itself, but it's easy to do from a shell script.  E.g.,

command="diff a b"
$command >output || {
  echo "$command"
  cat output
}

[Message part 3 (message/rfc822, inline)]
From: Peng Yu <pengyu.ut <at> gmail.com>
To: bug-diffutils <at> gnu.org
Subject: How to show the diff command when there is a difference when
 comparing two files?
Date: Sat, 1 Feb 2014 13:27:55 -0600
Hi,

The following shows that diff -r print the command e.g. "diff -r
/var/folders/ft/9trh7jt57kqc_hyq0wm5rny40000gx/T/tmp.wcrIdLELps/b.txt
/var/folders/ft/9trh7jt57kqc_hyq0wm5rny40000gx/T/tmp.AJieJ9Zk1O/b.txt"
if there is an error. I'm wondering if I just compare two files, it is
possible to print the diff command if there is a difference between
the two files? Thanks.

~/linux/test/gnu/diffutils/diff/-r$ cat main.sh
#!/usr/bin/env bash

dir1=$(mktemp -d)
dir2=$(mktemp -d)
echo 'Hello World' > "$dir1/a.txt"
echo 'Hello World' > "$dir2/a.txt"

echo 'Hello World' > "$dir1/b.txt"
echo 'Hello World!' > "$dir2/b.txt"

#echo 'Hello World' > "$dir1/c.txt"
echo 'Hello World' | gzip -n > "$dir1/c.txt.gz"
diff -r "$dir1" "$dir2"

~/linux/test/gnu/diffutils/diff/-r$ ./main.sh
diff -r /var/folders/ft/9trh7jt57kqc_hyq0wm5rny40000gx/T/tmp.wcrIdLELps/b.txt
/var/folders/ft/9trh7jt57kqc_hyq0wm5rny40000gx/T/tmp.AJieJ9Zk1O/b.txt
1c1
< Hello World
---
> Hello World!
Only in /var/folders/ft/9trh7jt57kqc_hyq0wm5rny40000gx/T/tmp.wcrIdLELps:
c.txt.gz

-- 
Regards,
Peng



This bug report was last modified 11 years and 57 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.