Question

hi i would like to use SED (Unix environment)in order to alternatively:

  • substitute double occurrence of a character with a single occurrence of the same character
  • substitute single character pattern with nothing

as example consider the following string

I want to substitute // character with / character.

I would like // to become / and / to become nothing. Therefore the final string will result as:

I want to substitute / character with character

Was it helpful?

Solution

This may work

sed  's:/\(/\)\{0,1\}:\1:g'

OTHER TIPS

This should do:

sed -e 's: / :  :g' -e 's: // : / :g' file

But not as good as 1_CRs solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top