user3451371 user3451371 - 1 year ago 97
Bash Question

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

Suppose I have a line like this:

aaaa ---- bbbb

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

Answer Source

Using sed:

s='aaaa ---- bbbb'
echo "$s"|sed 's/--* bb*/foo/'
aaaa foo
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download