[英]Creating directories from list preserving whitespaces
I have list of names in a file that I need to create directories from. 我有一个文件中的名称列表,我需要从中创建目录。 The list looks like
该列表看起来像
Ada Lovelace
Jean Bartik
Leah Culver
I need the folders to be the exact same, preserving the whitespace(s). 我需要文件夹完全相同,保留空格。 But with
但随着
awk '{print $0}' myfile | xargs mkdir
I create separate folders for each word 我为每个单词创建单独的文件夹
Ada
Lovelace
Jean
Bartik
Leah
Culver
Same happens with 同样如此
awk '{print $1 " " $2}' myfile | xargs mkdir
Where is the error? 错误在哪里?
Using gnu xargs
you can use -d
option to set delimiter as \\n
only. 使用
gnu xargs
您可以使用-d
选项将分隔符设置为\\n
only。 This way you can avoid awk
also. 这样你也可以避免使用
awk
。
xargs -d '\n' mkdir -p < file
If you don't have gnu xargs
then you can use tr
to convert all \\n
to \\0
first: 如果你没有
gnu xargs
那么你可以使用tr
将所有\\n
首先转换为\\0
:
tr '\n' '\0' < file | xargs -0 mkdir
@birgit:尝试:完全基于您提供的示例Input_file。
awk -vs1="\"" 'BEGIN{printf "mkdir ";}{printf("%s%s%s ",s1,$0,s1);} END{print ""}' Input_file | sh
awk '{ system ( sprintf( "mkdir \"%s\"", $0)) }' YourFile
# OR
awk '{ print"mkdir "\"" $0 "\"" | "/bin/sh" }' YourFile
# OR for 1 subshell
awk '{ Cmd = sprintf( "%s%smkdir \"%s\"", Cmd, (NR==1?"":"\n"), $0) } END { system ( Cmd ) }' YourFile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.