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

Bash `sed` regex grouping

I’m trying to turn a line like this to using sed I’m not really good with regex and I’m looking for some help with the sed command.

/Application/Lockscreen/ @smiths
/Application/BlueLock/ @egoists

to

path: */Application/Lockscreen/* @smiths
path: */Application/BlueLock/* @egoists

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

>Solution :

I would match on the first word [^ ]* then add the pre- and suffix to it \0:

$ sed 's/[^ ]*/path: *\0*/' input.txt
path: */Application/Lockscreen/* @smiths
path: */Application/BlueLock/* @egoists

Or if it makes more sense in your context replace the space with '* ' and the beginning ^ with 'path: ' (order matters):

$ sed 's/ /* /; s/^/path: */' input.txt
path: */Application/Lockscreen/* @smiths
path: */Application/BlueLock/* @egoists
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