complex transposing of columns with pure sed

纵饮孤独 提交于 2019-12-05 08:21:42

This might work for you (GNU sed):

sed -r ':a;$!N;s/^(([^ ]+ ).*)\n\2/\1,/;ta;P;D' file

or if you prefer:

sed -r ':a;$!N;s/^((\S+\s).*)\n\2/\1,/;ta;P;D' file

This reads 2 lines into the pattern space, compares the beginning of each line and if they are the same replaces the beginning of the second line that matches the first with a comma and repeats. If the lines do not match it prints out the first line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!