我有一个包含以下值的文本文件。
Id unit Date status
KGE1 1222 21-12-19 16:20 Deployed
KGE2 1222 21-12-19 16:20 Pending
我只想用逗号替换连续的空格。我正在使用以下命令,但它也在日期和时间之间添加逗号。请指导。
sed 's/ \{1,\}/,/g' txncount.txt > csvcount.txt
输出:
KGE1,1222,21-12-19,16:20,Deployed
KGE2,1222,21-12-19,16:20,Pending
KGE3,1222,21-12-19,16:21,Email_Sent
KGE4,1222,21-12-19,15:00,Pending
KGE5,1222,21-12-19,15:10,Deployed
预期输出:
KGE1,1222,21-12-19 16:20,Deployed
KGE2,1222,21-12-19 16:20,Pending
KGE3,1222,21-12-19 16:21,Email_Sent
KGE4,1222,21-12-19 15:00,Pending
KGE5,1222,21-12-19 15:10,Deployed
它应该仅用逗号替换两个或更多空格的连续逗号。
答案1
它是<txncount.txt sed -r 's/ {2,}/,/g' >csvcount.txt