Adding quotations at beginning and end of a line using sed
[^$]
means "any character except the dollar sign". So saying sed 's/[^$]/"/g'
you are replacing all characters with "
, except $
(credits to Ed Morton):
$ echo 'he^llo$you' | sed 's/[^$]/"/g'
""""""$"""
To say: match either ^
or $
, you need to use the ( | )
expression:
sed 's/\(^\|$\)/"/g' file
or, if you have -r
in your sed
:
sed -r 's/(^|$)/"/g' file
Test
$ cat a
hello
bye
$ sed -r 's/(^|$)/"/g' a
"hello"
"bye"
sed 's/.*/"&"/' YourFile
Will do the same using full line as pattern replacement &
.
In this case g
is not needed because you only have 1 occurrence of the whole line per line (default behaviour of sed
reading line by line)