操纵输入文件并使用awk创建一个新文件

时间:2017-11-14 01:07:25

标签: awk

输入

1473697,5342715,256,0.3

1473697,7028427,256,0.1

1473697,5342716,256,0.3

1473697,5342715,257,0.3

1473697,7028427,257,0.1

1473610,7028427,256,0.1

1473610,5342715,256,0.3

1473610,7028422,256,0.1

输出

1473697,256,5342715 0.3 7028427 0.1 5342716 0.3

1473697,257,5342715 0.3 7028427 0.1

1473610,256,7028427 0.1 5342715 0.3 7028422 0.1

OFSFS=, 有没有办法根据第1列和第3列搜索唯一的行 然后使用第2列和第4列的详细信息打印该行

1 个答案:

答案 0 :(得分:0)

需要一段时间来弄清楚你想要什么,但我认为你正在寻找:

awk '!a[$1 $3] {a[$1 $3] = $1","$3","} 
    {a[$1 $3] = a[$1 $3] " " $2 " " $4}
    END {for(i in a) print a[i]}' FS=, input-file

awk '{a[$1","$3] = a[$1","$3] " " $2 " " $4}
    END {for(i in a) print i","a[i]}' FS=, input-file

主题有很多变化。