如果我有一个包含许多链接的文档,并且我想特别下载一张名为 www.website.de/picture/example_2015-06-15.jpeg 的图片,我该如何编写一个命令来自动下载我提取的这张图片出我的文件?
我的想法是这样,但我会收到一条失败消息,如“wget:URL 丢失”:
grep -E 'www.website.de/picture/example_2015-06-15.jpeg' document | wget
Run Code Online (Sandbox Code Playgroud)
使用 xargs:
grep etc... | xargs wget
Run Code Online (Sandbox Code Playgroud)
它接受其标准输入(grep 的输出),并将该文本作为命令行参数传递给您告诉它的任何应用程序。
例如,
echo hello | xargs echo 'from xargs '
Run Code Online (Sandbox Code Playgroud)
产生:
from xargs hello
Run Code Online (Sandbox Code Playgroud)
使用反引号将是最简单的方法:
wget `grep -E 'www.website.de/picture/example_2015-06-15.jpeg' document`
Run Code Online (Sandbox Code Playgroud)