0

我想对文件进行区分,一个是本地的,另一个是在线的,例如

opendiff http://www.tex.ac.uk/ctan/web/lua2dox/Doxyfile Doxyfile

但它抛出以下错误:

2014-02-12 15:23:43.579 opendiff[72650:1007] /Users/Dev/Joker/http:/www.tex.ac.uk/ctan/web/lua2dox/Doxyfile 不存在

那么我怎样才能像使用本地文件一样使用在线文件呢?

4

1 回答 1

1

由于这是一个编程问答网站,我们不妨编写一个程序来为我们做这件事:-)

您可以创建一个名为(例如)的脚本,odw用于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

在这种情况下,我们将基于 Web 的文件检测为以http://. 如果是,我们只需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>

现在有各种可以进入该脚本的附加内容,将标志传递给diffwget程序的能力,处理其他 URL 类型的能力,删除信号上的临时文件等等。

但它应该足以让你开始。

于 2014-09-25T08:38:55.983 回答