Unix 生成连续编号的URL
我想生成一个包含以下行的文本文件:Unix 生成连续编号的URL,unix,url,text-files,generate,numbered,Unix,Url,Text Files,Generate,Numbered,我想生成一个包含以下行的文本文件: http://example.com/file1.pdf http://example.com/file2.pdf http://example.com/file3.pdf . . http://example.com/file1000.pdf 请问,有谁能建议如何使用unix命令行执行此操作 谢谢可以创建/运行python脚本文件来生成此脚本。使用vim、nano或任何其他终端编辑器,创建一个python文件,如下所示: def genFile(fn, s
http://example.com/file1.pdf
http://example.com/file2.pdf
http://example.com/file3.pdf
.
.
http://example.com/file1000.pdf
请问,有谁能建议如何使用unix命令行执行此操作
谢谢可以创建/运行python脚本文件来生成此脚本。使用vim、nano或任何其他终端编辑器,创建一个python文件,如下所示:
def genFile(fn, start, end):
with open(fn, "w+") as f:
f.writelines([f"http://example.com/file{str(i)}.pdf\n" for i in range(start, end+1)])
try:
fn = input("File Path: ") # can be relative
start = int(input("Start: ")) # inclusive
end = int(input("End: ")) # inclusive
genFile(fn, start, end)
except:
print("Invalid Input")
将其写入文件后,我们将其称为script.py。我们可以运行以下命令来执行脚本:
python script.py
然后,填写文件路径、开始和结束的提示。这将导致在指定的文件中打印所有由“\n”分隔的行。带有一个交互for循环
for (( i=1;i<=1000;i++ ));
do
echo "http://example.com/file$i.pdf";
done > newfile
((i=1;i新文件)的
随附:
while read i;
do
echo "http://example.com/file$i.pdf";
done <<< $(seq 1000) > newfile
阅读时;
做
回声“http://example.com/file$i.pdf”;
你试过什么了?也许你可以建议一些解决方案,告诉我们什么具体不起作用。谢谢大家!在我的Mac电脑上,我使用这个:print-l'http://example.com/file“{1..1000}.pdf>newfile
在我的Unix机器上,我使用这个(由Raman Sailopal编写),它也在Mac上工作:用于((i=1;i newfile;
太好了。如果建议符合您的要求,请您投票并接受解决方案。