bash 带有输入文件和输出文件的 Wget

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2046287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:32:32  来源:igfitidea点击:

Wget with input-file and output-document

bashwgetxargs

提问by Chopstickz

I have a list of URLs which I would like to feed into wget using --input-file.

我有一个 URL 列表,我想使用 --input-file 将其输入 wget。

However I can't work out how to control the --output-document value at the same time, which is simple if you issue the commands one by one. I would like to save each document as the MD5 of its URL.

但是我不知道如何同时控制 --output-document 值,如果你一个一个地发出命令,这很简单。我想将每个文档保存为其 URL 的 MD5。

 cat url-list.txt | xargs -P 4 wget

And xargs is there because I also want to make use of the max-procs features for parallel downloads.

xargs 在那里是因为我还想利用 max-procs 功能进行并行下载。

采纳答案by ghostdog74

how about using a loop?

使用循环怎么样?

while read -r line
do
   md5=$(echo "$line"|md5sum)
   wget ... $line ... --output-document $md5 ......
done < url-list.txt

回答by Paused until further notice.

Don't use cat. You can have xargsread from a file. From the manpage:

不要使用cat. 您可以xargs从文件中读取。从man页面:

       --arg-file=file
       -a file
              Read items from file instead of standard input.  If you use this
              option, stdin remains unchanged when commands are  run.   Other‐
              wise, stdin is redirected from /dev/null.

回答by Ole Tange

In your question you use -P 4 which suggests you want your solution to run in parallel. GNU Parallel http://www.gnu.org/software/parallel/may help you:

在您的问题中,您使用 -P 4 这表明您希望您的解决方案并行运行。GNU Parallel http://www.gnu.org/software/parallel/可以帮助您:

cat url-list.txt | parallel 'wget {} --output-document "`echo {}|md5sum`"'

回答by kjshim

You can do that like this :

你可以这样做:

cat url-list.txt | while read url; do wget $url -O $( echo "$url" | md5 ); done

cat url-list.txt | 读取网址时;做 wget $url -O $( echo "$url" | md5 ); 完毕

good luck

祝你好运