我想生成一个包含以下行的文本文件:
http://example.com/file1.pdf
http://example.com/file2.pdf
http://example.com/file3.pdf
.
.
http://example.com/file1000.pdf
请问有人可以建议如何使用unix命令行来做到这一点吗?
谢谢
我想生成一个包含以下行的文本文件:
http://example.com/file1.pdf
http://example.com/file2.pdf
http://example.com/file3.pdf
.
.
http://example.com/file1000.pdf
请问有人可以建议如何使用unix命令行来做到这一点吗?
谢谢
带有一个交互 for 循环
for (( i=1;i<=1000;i++ ));
do
echo "http://example.com/file$i.pdf";
done > newfile
带序列:
while read i;
do
echo "http://example.com/file$i.pdf";
done <<< $(seq 1000) > newfile
可以创建/运行 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”分隔的指定文件中。