作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 txt 文件,其中包含太多要下载的直接链接,包括每个 url 前面的文件的每个名称,txt 文件如下所示:
http://example.com/file1.png name_of_the_file1
http://example.com/file2.mp4 name_of_the_file2
http://example.com/file3.mkv name_of_the_file3
http://example.com/file4.png name_of_the_file4
http://example.com/file5.avi name_of_the_file5
如您所见,文件名和 url 用空格分隔。
wget
将它们重命名为各自的名称.
http://example.com/47188.png Abaixo de Zero (2021)
最佳答案
您可以使用这个 awk|xargs 单行:
awk '{url=$1; $1="";{sub(/ /,"");out=url" -O \""$0"\""}; print out}' file.txt | xargs -L 1 wget
解释:
url=$1 # temp var inside awk
$1="" # replace url with null space
{sub(/ /,"");out=url" -O \""$0"\""} # need to output var
sub(/ /,"") # need to trim leading white space
out=url" -O \""$0"\"" # line formatting with escaping characters
print out # シ
xargs -L 1 wget # get awk output line by line to wget
plus some awk sintax sugar
例子:
cat << EOF >> file.txt
https://www.openssl.org/source/old/1.1.1/openssl-1.1.1k.tar.gz name_of_the_file2
https://www.openssl.org/source/old/1.1.1/openssl-1.1.1j.tar.gz name of_the_file3
https://www.openssl.org/source/old/1.1.1/openssl-1.1.1i.tar.gz name of the_file4
https://www.openssl.org/source/old/1.1.1/openssl-1.1.1h.tar.gz name of the file5
EOF
awk '{url=$1; $1="";{sub(/ /,"");out=url" -O \""$0"\""}; print out}' file.txt | xargs -L 1 wget
ls -1
name_of_the_file2
'name of_the_file3'
'name of the_file4'
'name of the file5'
关于linux - 如何使用 wget 与 .txt 文件中的许多 URL 下载并另存为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70759177/
我有 json 数据: { "products": [ { "productId" : 0, "productImg" : "../img/product-ph
我是一名优秀的程序员,十分优秀!