简体   繁体   English

将两行与 bash 结合

[英]Combining two lines with bash

I want to merge two lines from csv file:我想从 csv 文件中合并两行:

x,,x
,x,

to get:要得到:

x,x,x

Can you help me?你能帮助我吗?

Edit: I have many combination of x occurence (x,, or ,x,x ...)编辑:我有很多 x 出现的组合 (x,, or ,x,x ...)

I give you other example.我再给你举个例子。 First column of file contains linux distribution name ,second column is command, if in third column exists "x" it means that command is available in centos 5, if in fourth column exists "x" it means that command is in centos 6, and if "x" is in the last field it means that is available in centos 7.文件的第一列包含linux发行版名称,第二列是命令,如果第三列存在“x”,则表示该命令在centos 5中可用,如果第四列中存在“x”,则表示该命令在centos 6中,以及如果“x”在最后一个字段中,则表示在 centos 7 中可用。

centos,ls,,,x
centos,ls,x,x,

And now I want to have one record which will summarize info about command.现在我想要一个记录来总结有关命令的信息。

尝试这个 :

sed ':a;$!N;s/,$//;s/^,//;s/\n//g;ta;s/,,*/,/g' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM