我需要从File1,File2,...到File99调用文件。

我尝试了以下不成功的

cat test > {File1 .. File99}

没有单词File的命令不起作用。

有帮助吗?

解决方案

只需一个命令:

touch File{1..99}

其他提示

$ for i in {1..100}; do touch "File$i"; done 

这取决于您使用的shell。我假设您正在使用Bash。

根据 http://www.gnu.org /software/bash/manual/bashref.html#Brace-Expansion ,Bash将扩展数字和单个字符。所以你的大括号表达应该是:

File{1..99}

但我不认为重定向运算符<!>“; <!> gt; <!>”;可以输出到多个文件。您可能需要使用循环:

for output in File{1..99}
do
    cat test > $output
done

或者作为一个单行:

for output in File{1..99}; do cat test > $output; done

如果你喜欢非循环版本,那么你可以使用tee

cat test | tee File{1..99} > /dev/null

使用 zsh (及其 mult_ios ),您可以:)

% zsh -c 'print test > file{1..3}' 
% head file*                      
==> file1 <==
test

==> file2 <==
test

==> file3 <==
test

如果您希望文件正确排序(file01,file02 ... file10等),请执行以下操作:

for i in {0..10}; do i="0"$i; touch file${i: -2}; done

与以下内容相同:

for i in {0..10}
do
    i="0"$i
    touch file${i: -2} # or cat file > file${i: -2}
done

子字符串扩展子句中冒号和短划线之间必须有空格。如果你想以<!>“file01 <!>”开头,你可以用1开始上面的范围。

或者,更简洁的方法是拥有前导零:

touch file{0..9}{0..9}

并使用phyrex1an的技巧:

cat test | tee File{0..9}{0..9} > /dev/null

这会产生一个额外的文件<!>“file00 <!>”;你也可以做<!>“; {2..3} {0..9} <!>”; for <!> quot; file20 <!> quot;通过<!> quot; file39 <!>“;但是,更改个位数(第二个范围)会导致跳过序列的某些部分。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top