如何使用sed用逗号替换空格? [英] How to replace space with comma using sed?

查看:163
本文介绍了如何使用sed用逗号替换空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用逗号分隔符替换每个字段之间的空格.谁能告诉我我该怎么做.我尝试了下面的命令,但它不起作用.谢谢.

I would like to replace the empty space between each and every field with comma delimiter.Could someone let me know how can I do this.I tried the below command but it doesn't work.thanks.

My command:
:%s//,/


53 51097 310780 1
56 260 1925 1
68 51282 278770 1
77 46903 281485 1
82 475 2600 1
84 433 3395 1
96 212 1545 1
163 373819 1006375 1
204 36917 117195 1

推荐答案

如果你在谈论 sed,这是有效的:

If you are talking about sed, this works:

sed -e "s/ /,/g" < a.txt

vim 中,使用相同的正则表达式替换:

In vim, use same regex to replace:

s/ /,/g

这篇关于如何使用sed用逗号替换空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆