[英]How to create folder per each line of a file?
I want create per each line of text file create nested directory.我想为每行文本文件创建嵌套目录。
for (( i=0;i<=$(cat filename | wc -l);i++ ))
do
mkdir /PATH/$i
done
You are missing the third part of for (( init; condition; increment))
.您缺少for (( init; condition; increment))
的第三部分。 The correct version should be正确的版本应该是
for (( i=0; i<=$(cat filename | wc -l); i++ )); do
mkdir /PATH/$i
done
However, this is a very crude way to tackle the problem.然而,这是解决问题的一种非常粗略的方法。 A better approach would be the following (courtesy of tripleee)以下是更好的方法(由 Tripleee 提供)
seq 0 $(wc -l <filename) | xargs -I mkdir /PATH/{}
Note that both commands will create one directory more than the file has lines.请注意,这两个命令都将创建一个多于文件行数的目录。 For a file with two lines the directories 0
, 1
, and 2
will be created.对于具有两行的文件,将创建目录0
、 1
和2
。 If this was an bug in your original script, change the 0
in the scripts to 1
.如果这是您原始脚本中的错误,请将脚本中的0
更改为1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.