如何将 wget 与输入文件和文件名一起使用

Mat*_*att 2 wget input

我有一个文本文件,其中包含 10,000 个带有唯一编号的 url,我想将文件另存为。每行有一个 10 个字符的代码,然后是要检索的图像的 URL。如何让输入文件使用前 10 个字符作为 wget 文件名?

这是输入文件的示例:input.txt

x100083590http://image.allmusic.com/13/adg/cov200/drt200/t291/t29123q8m19.jpg
b200149548http://ecx.images-amazon.com/images/I/41DoH%2BAWKEL.jpg
z100151855http://image.allmusic.com/13/amg/cov200/dri400/i450/i45035hxdrb.jpg
p400171646http://ecx.images-amazon.com/images/I/61cH4n34IhL.jpg
Run Code Online (Sandbox Code Playgroud)

wget -i input.txt 将获得该文件,但不具有前面的唯一编号。

我想t29123q8m19.jpg(第一行)被保存为x100083590.jpg

如果有更好的方法来写出输入文件,先说 URL,那么我也可以这样做,但我永远不会知道第一个字段的长度。现在,前 10 个字符将始终是我想将 wget 图像另存为的字符。

编辑 这是在 Windows 环境中完成的。

Pau*_*aul 6

在Linux中。

 while read p; do
   newname=${p:0:10} # first 10 chars
   url=${p:10} # remaining chars after the 10th
   wget $url -O $newname.jpg  #get url and output to new filename
 done < input.txt
Run Code Online (Sandbox Code Playgroud)

在windows下,我们可以这样做:

 SETLOCAL ENABLEDELAYEDEXPANSION
 for /f %%p in (input.txt) do (
    SET p1=$$p
    SET newname=!p1:~0,10!
    SET url=!p1:~10!
    wget %url% -O %newname%.jpg
 )
Run Code Online (Sandbox Code Playgroud)