示例输入文件:
[x@x test]$ cat test.txt
a1|1
a1|2
a1|3
b1|1
b1|4
b2|4
b3|5
执行:
./test.sh test.txt
输出文件:
[x@x test]$ cat test.txt_output
a1|1,2,3
b1|1,4
b2|4
b3|5
脚本:
本文介绍如何利用awk命令根据某列相同的key将多行合并为一行,并统计这种一对多的情况。示例中展示了一种具体操作方法,包括调整输出格式的过程。
示例输入文件:
[x@x test]$ cat test.txt
a1|1
a1|2
a1|3
b1|1
b1|4
b2|4
b3|5
执行:
./test.sh test.txt
输出文件:
[x@x test]$ cat test.txt_output
a1|1,2,3
b1|1,4
b2|4
b3|5
脚本:
1147

被折叠的 条评论
为什么被折叠?