Chinaunix

标题: 文件处理紧急求助 [打印本页]

作者: 93237984    时间: 2008-11-10 09:24
标题: 文件处理紧急求助
文件a格式如下:

file1 a b c
file2 a b c
file3 a b c
file4 f f b
file5 f f b

在suse下如何用shell改成如下格式:
file1,file2,file3 a b c
file4,file5 f f b

就是把后三列相同的行的第一列进行合并,合并的第一列用逗号分割
作者: waker    时间: 2008-11-10 09:32
  1. awk '{a[$2" "$3" "$4]=a[$2" "$3" "$4]((a[$2" "$3" "$4])?",":"")$1}
  2. END{for(i in a)print a[i],i}' urfile
复制代码

作者: biglazybug    时间: 2008-11-10 11:01
标题: 回复 #2 waker 的帖子
这个好强! 版主内功深厚啊
作者: rdcwayx    时间: 2008-11-10 13:23
很实用。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2