How to replace one character inside parentheses keep everything else as is

后端 未结 5 1126
北恋
北恋 2021-01-19 06:48

The data looks like this :

There is stuff here (word, word number phrases)
(word number anything, word phrases), even more
...

There is a l

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-19 07:32

    Assuming there's only one comma to be replaced inside parentheses, this POSIX BRE sed expression will replace it with colon:

    sed 's/(\(.*\),\(.*\))/(\1:\2)/g' file
    

    If there are more than one comma, only the last one will be replaced.

    In multiple-commas scenario, you can replace only the first one with:

    sed 's/(\([^,]*\),\([^)]*\))/(\1:\2)/g' file
    

提交回复
热议问题