2

我有一个如下的数据集

first 0 1
first 1 2
first 2 3
second 0 1
second 1 2
second 2 3
third 0 1 
third 1 2
third 2 3

我需要检查这个文件并提取第一、第二和第三列的第三列并将它们存储在不同的文件中。

输出文件应包含:

1
2
3
4

1 回答 1

9

这非常简单,awk '{print $3>$1}' file 打印第三个字段并将输出重定向到文件,其中文件名是第一个字段。

演示:

$ ls 
file

$ awk '{print $3>$1}' file

$ ls
file  first  second  third

$ cat first
1
2
3

$ cat second 
1
2
3

$ cat third 
1
2
3
于 2013-05-23T09:31:59.273 回答