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

SED Replace character with '

Trying to put ' before each line of text and ' at the end of each line of text.

I have been using sed 's/^/1/' file.txt to replace to begging of each line and sed 's/$/0/' file.txt to replace the end of each line.

What I am trying to make work is sed 's/^/'/' and sed 's/$/'/'

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 would format my file to make each line reach as a command, when applied to a separate script.

>Solution :

echo abc | sed "s/.*/'&'/"

Output:

'abc'

From man sed:

The replacement may contain the special character & to refer to that portion of the pattern space which
matched

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