8

Am I able to compare two different urls/websites without downloading the file first using wget or something similar first. I tried the following, but received the below error.

[root@desktop ~]# diff http://www.example.net/index.php http://www.example.com/index.php
diff: http://www.example.net/index.php: No such file or directory
diff: http://www.example.com/index.php: No such file or directory
[root@desktop ~]#
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • 3
    diff works only with files, not with URLs – Jabberwocky Mar 25 '14 at 10:48
  • @MichaelWalz Is there a different command which would work with urls? – user1032531 Mar 25 '14 at 10:49
  • Not that I know, but I'm not a Linux specialist. You could make a small script that downloads both URLs to /tmp and the laucnhes diff on those files. – Jabberwocky Mar 25 '14 at 10:50
  • 1
    Actually you could use `diff` with process substitution. `diff <(echo "http://www.example.com/index.php" ) <(echo "http://www.example.net/index.php")` (Do you want to compare urls or the page itself ?) –  Mar 25 '14 at 10:53

1 Answers1

17

Of course you can use curl, although it is a bit strange:

diff <(curl url1) <(curl url2)

In your case:

diff <(curl http://www.example.net/index.php) <(curl http://www.example.com/index.php)

Note you can use curl -s for a cleaner diff execution.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Thanks fedorqui, Is `curl` preferred over Paulloz's example with `echo`? – user1032531 Mar 25 '14 at 10:57
  • `curl` will compare pages itself, while `echo` the strings. – fedorqui Mar 25 '14 at 10:57
  • OK, I'm interested @fedorqui. Why is using curl to do diff 'a bit strange'? – notapatch Oct 21 '15 at 12:35
  • 2
    @Rich I said "a bit strange" because of the syntax. We normally say `diff file1 file2`, whereas using [process substitution](http://stackoverflow.com/a/31703275/1983854) looks a bit weird the first. But it is completely valid and a very useful way to do it once you learn it : ) – fedorqui Oct 21 '15 at 16:07