【发布时间】:2022-01-11 01:25:45
【问题描述】:
我正在尝试从 .txt 文件中的 URL 列表下载 PDF 文件,每行一个 URL。 ('urls.txt')
当我使用以下命令时,我使用的 URL 是 .txt 文件第一行的精确复制粘贴:
$ curl http://www.isuresults.com/results/season1617/gpchn2016/gpchn2016_protocol.pdf -o 'test.pdf'
pdf 下载完美。但是,当我使用此命令时:
xargs -n 1 curl -O < urls.txt
然后我收到一个“卷曲:(3) URL 使用错误/非法格式或缺少 URL”错误 x 倍于 .txt 文件中列出的 URL 数量。我已经单独测试了许多 URL,它们似乎都可以正常下载。
我该如何解决这个问题?
编辑——urls.txt的前三行内容如下:
http://www.isuresults.com/results/season1718/gpf1718/gpf2017_protocol.pdf
http://www.isuresults.com/results/season1718/gpcan2017/gpcan2017_protocol.pdf
http://www.isuresults.com/results/season1718/gprus2017/gprus2017_protocol.pdf
已解决:根据下面的评论,问题在于 .txt 文件是 DOS/Windows 格式。我使用以下代码对其进行了转换:
$ dos2unix urls.txt
然后使用我的原始代码行完美下载文件。有关更多信息,请参阅此线程:Are shell scripts sensitive to encoding and line endings?
感谢所有回复的人!
【问题讨论】:
-
听起来你的 urls.txt 文件是 DOS/Windows 格式,这会混淆 unix 工具。请参阅"Are shell scripts sensitive to encoding and line endings?"(尤其是 Anthony Geoghegan 的回答)。