Can't pipe into diff?

I wanted to be clever and compare a remote file to a local file without first manually downloading it. I can get the contents of the remote file by

ssh user@remote-host "cat path/file.name"

However, piping that to diff

ssh user@remote-host "cat path/file.name" | diff path/file.name

gives me this:

diff: missing operand after `path/file.nae'
diff: Try `diff --help' for more information.

I have ssh keys set up, so it’s not prompting me for a password. What’s a workaround for this?

Asked By: user394

||

Piping into diff is equivalent to running

diff path/file.name

and then, once it’s running, typing the entire contents of the file.

As you can see, that’s not what you expected.

Answered By: Macha

Use - to represent the standard input:

ssh user@remote-host "cat path/file.name" | diff path/file.name -
Answered By: Hemant

Here’s one workaround: diff seems to accept <(expr) as arguemnts:

diff <(ssh "cat path/file.name/") <(cat path/file.name)
Answered By: user394
diff /tmp/localtempfile <(ssh -A -o StrictHostKeyChecking=no root@server "cat /tmp/remotetempfile")
Answered By: Vlad
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.