SED Replace character with '

Viewed 31

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/$/'/'

This would format my file to make each line reach as a command, when applied to a separate script.

1 Answers
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

Related