简体   繁体   English

如何为文件的每一行创建文件夹?

[英]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.对于具有两行的文件,将创建目录012 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.

相关问题 如何在每个文件夹中创建一个文件? - How can I create a file in each folder? Linux shell:LOOP用于在每个文件夹中创建文件 - Linux shell: LOOP for create file in each folder 使用GREP查找是否在特定文件夹中找到文件的每一行 - Using GREP to find if each line of a file is found in a particular folder 如何在现有文件夹树中(在每个现有文件夹中)递归创建文件夹? - How to create a folder recursively in an existing tree of folders (in each existing folder)? 导出文件的每一行(最后一行除外)以使用 AWK 为每一行创建一个新文件 - Export every line (excpet last line ) of a file to create a new file for each line using AWK 如何从文件的每一行中获取元素,并将它们添加到不同文件每一行的每个条目中? - How to take elements from each line of a file, and prepend them to each entry in each line of a different file? 如何将文件中的每一行作为参数传递给脚本? - How to pass each line in a file as argument to a script? 如何为给定路径创建文件夹结构和文件 - How to create the folder structure and the file for a given path 如何遍历文件并用行号回显每一行 - How to loop through file and echo each line with line number 如何使用命令行在Atom中创建文件和文件夹? - How to create files and folder in Atom using the command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM