字符串中第一次出现字符。需要正则表达式

时间:2012-01-13 16:52:42

标签: regex

我有一些这样的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

的其余部分

关于正则表达式的任何想法?尝试了几件不同的事情,似乎无法让它发挥作用......

2 个答案:

答案 0 :(得分:0)

你的问题不是很明确,我只举一个例子,希望它对你有所帮助:

 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

答案 1 :(得分:0)

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

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

替换文字

$1 $2

http://refiddle.com/1ot

在线查看