我想区别一下online,一个是本地的,另一个是在线的,例如
opendiff http://www.tex.ac.uk/ctan/web/lua2dox/Doxyfile Doxyfile但它会引发以下错误:
2014-02-12 15:23:43.579 opendiff72650:1007 /Users/Dev/Joker/http:/www.tex.ac.uk/ctan/web/lua2dox/Doxyfile不存在
那么,我如何以与本地文件相同的方式使用在线文件呢?
发布于 2014-09-25 08:38:55
由于这是一个编程问答站点,我们不妨编写一个程序来为我们这样做:-)
您可以创建一个名为odw for OpenDiffWeb的脚本,该脚本将检测您是否试图访问基于web的文件,并首先将它们下载到临时位置。
检查下面的脚本,它是非常基本的,但它显示了可以采取的方法。
#!/bin/bash
# Ensure two parameters.
if [[ $# -ne 2 ]] ; then
echo Usage: $0 '<file/url-1> <file/url-2>'
exit 1
fi
# Download first file if web-based.
fspec1=$1
if [[ $fspec1 =~ http:// ]] ; then
wget --output-document=/tmp/odw.$$.1 $fspec1
fspec1=/tmp/odw.$$.1
fi
# Download second file if web-based.
fspec2=$2
if [[ $fspec2 =~ http:// ]] ; then
wget --output-document=/tmp/odw.$$.2 $fspec2
fspec2=/tmp/odw.$$.2
fi
# Show difference of two files.
diff $fspec1 $fspec2
# Delete them if they were web-based.
if [[ $fspec1 =~ /tmp/odw. ]] ; then
rm -f $fspec1
fi
if [[ $fspec2 =~ /tmp/odw. ]] ; then
rm -f $fspec2
fi在本例中,我们从http://开始检测一个基于web的文件。如果是的话,我们只需使用wget将其降到临时位置。这两个文件都是这样检查的。
一旦两个文件都在本地磁盘上(要么是因为它们被关闭,要么是因为它们已经存在),您就可以运行diff了--我已经使用了标准的diff,但是您可以替换自己的文件。
然后,清理临时文件。
作为测试,我下载了页面http://www.example.com并对其做了非常小的更改,然后将页面与修改后的本地副本进行比较:
pax> odw http://www.example.com example.txt
--2014-09-25 16:40:02-- http://www.example.com/
Resolving www.example.com (www.example.com)... 93.184.216.119,
2606:2800:220:6d:26bf:1447:1097:aa7
Connecting to www.example.com (www.example.com)|93.184.216.119|:80...
connected.
HTTP request sent, awaiting response... 200 OK
Length: 1270 (1.2K) [text/html]
Saving to: `/tmp/odw.6569.1'
100%[=================================>] 1,270 --.-K/s in 0s
2014-09-25 16:40:02 (165 MB/s) - `/tmp/odw.6569.1' saved [1270/1270]
4c4
< <title>Example Domain</title>
---
> <title>Example Domain (slightly modified)</title>现在,可以在脚本中添加各种各样的内容,将标志传递给diff和wget程序,处理其他URL类型,删除信号上的临时文件等等。
但希望这足以让你开始工作。
https://stackoverflow.com/questions/21730948
复制相似问题