Skip to content
Advertisement

How to use sed command to replace the string in linux?

I have String like below .

JavaScript

Basically I need to look for the last colon (:) and Replace everything after last colon(:) .

Output for the above string : hd_ma_prod_customer_ro:*:123456789:replacedString

By using sed how can I do this.Any one help me.

Advertisement

Answer

The following sed command will do what you want:

JavaScript

What it’s replacing is a colon followed by any number of non-colons, at the end of the string.

What it replaces it with is the colon plus your text.

See the following transcript for details:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement