regex 字符串中第一个出现的字符,需要正则表达式

eivgtgni  于 2023-05-08  发布在  其他
关注(0)|答案(2)|浏览(117)

我有一些这样的CSV数据:

1325318514,197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536,196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557,196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578,196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0
....

我想替换第一个,在每个字符串上都有一个空格,但不替换其余的,s
有什么关于正则表达式的想法吗?尝试了几种不同的方法,似乎都不能让它起作用。

o7jaxewo

o7jaxewo1#

你的问题不是很清楚,我只是给予个例子,希望对你有帮助:

sed 's/,/ /1' <<<"1325318514,197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536,196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557,196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578,196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0"

输出:

1325318514 197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536 196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557 196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578 196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0
dm7nw8vv

dm7nw8vv2#

在大多数正则表达式实现中,使用模式

/([^,]*),(.*)/gm

和替换文本

$1 $2

相关问题