Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove anything enclosed in : from a text?

I have a text which includes multiple substrings like :xxx: which should be removed using awk. The xxx-part could be any string but cannot contain white spaces or line breaks.

Here is an example text:

This is sample text:hello:
It might include normal colons like : or: that have to remain. :hello-world: 

The command should turn that text into:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is sample text 
It might include normal colons like : or: that have to remain.

My pathetic attempt:

awk '{gsub(":.*:","")}1'

>Solution :

Using sed

$ sed 's/:[^ \|:]*://g' input_file
This is sample text
It might include normal colons like : or: that have to remain.

Using awk

$ awk -F":[^:| ]*:" '{print $(NF-1)}' input_file
This is sample text
It might include normal colons like : or: that have to remain.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading