如何从一个文本文件中的列表中创建多个文件? [英] How to Create several files from a list in a text file?
问题描述
说我有其中包含文件名(无空格)的文件列表:
Say I have a list in a file which contains filenames (without spaces):
filename
othername
somethingelse
...
- 每行后跟一个CR,一个文件名每行
是否有某种联系的脚本,我可以用它来创建数百个文件,通过一个列表中设置标题?
Is there some kind of touch script I can use to create hundreds of files with titles set by a list?
这也将是令人难以置信的有益的,如果我可以填补每一个文件,在创建内容。
It would also be incredibly helpful if I could fill each file with content upon creation.
任何抨击有任何提示:我使用Ubuntu 10.04
Any bashers have any tips: I'm using Ubuntu 10.04
感谢
推荐答案
要简单地创建文件,假设 file_full_of_files_names
是空格分隔的文件名的文本文件:
To simply create the files, assuming that file_full_of_files_names
is a text file with whitespace-delimited filenames:
cat file_full_of_files_names | xargs touch
要真正与内容填充它们首先,从一个名为 initial_content
:
To actually fill them with content first, from a file called initial_content
:
cat file_full_of_files_names | tr ' \t' '\n\n' | while read filename; do
if test -f "$filename"; then
echo "Skipping \"$filename\", it already exists"
else
cp -i initial_content "$filename"
fi
done
这篇关于如何从一个文本文件中的列表中创建多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!