擅长:python、mysql、java
<p>输出重定向右侧的未附加表达式是未定义的行为。试试<code>awk '{print > ("file" ++a[$1] ".txt")}' input</code>。你知道吗</p>
<p>如果有太多的文件同时打开是一个问题,那么得到GNU awk,但如果你不能:</p>
<pre><code>$ ls
fileA.txt
$ awk '{f="file" ++a[$1] ".txt"; print >> f; close(f)}' fileA.txt
$ ls
file1.txt file2.txt file3.txt file4.txt fileA.txt
$ cat file1.txt
1 Cat
2 Boy
3 Tree
</code></pre>