sed -i 's/$/\'/g'
sed -i "s/$/\'/g"
How to escape both $
and '
by 1 command?
sed -i 's/$/\'/g'
sed -i "s/$/\'/g"
How to escape both $
and '
by 1 command?
To add a quote at the end of a line use
sed -i "s/$/'/g" file
sed -i 's/$/'"'"'/g' file
See proof.
If there are already single quotes, and you want to make sure there is single occurrence at the end of string use
sed -i "s/'*$/'/g" file
sed -i 's/'"'*"'$/'"'"'/g' file
See this proof.
To escape $
and '
chars use
sed -i "s/[\$']/\\\\&/g" file
See proof
[\$']
- matches $
(escaped as in double quotes it can be treated as a variable interpolation char) or '
\\\\&
- a backslash (need 4, that is literal 2 backslashes, it is special in the replacement), and &
is the whole match.Just don't use single quotes to start the sed script?
sed "s/$/'/"
The /g
at the end means to apply everywhere it's found on each stream (line) - you don't need this since $
is a special character indicating end of stream.
This might work for you (GNU sed):
sed 's/$/'\''/' file
Adds a single quote to the end of a line.
sed 's/\$/'\''/' file
Replaces a $
by a single quote.
sed 's/\$$/'\''/' file
Replaces a $
at the end of line by a single quote.
N.B. Surrounding sed commands by double quotes is fine for some interpolation but may return unexpected results.
Use octal
values
sed 's/$/\o47/'
Care to use backslash
+
letter o minus
+
octal number 1 to 3 digit