SED substituting double character pattern with single character of the pattern

StackOverflow https://stackoverflow.com/questions/23567205

  •  19-07-2023
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

This may work

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

Andere Tipps

This should do:

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

But not as good as 1_CRs solution

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top