How to replace a sentence with space on the basis of a pattern if it occurs in the middle of a sentence

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

  •  19-06-2023
  •  | 
  •  

Frage

Suppose I have a line like this:

aaaa ---- bbbb

I want to erase the ----bbbb part, but I want to keep the aaaa part as it is in the file. How can I do it?

War es hilfreich?

Lösung

Using sed:

s='aaaa ---- bbbb'
echo "$s"|sed 's/--* bb*/foo/'
aaaa foo
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top