// plain
The sed
command line utility can be used to add quotes around a string. The syntax is as follows:
sed 's/^/"/; s/$/"/'
This command will add double quotes around the string. The s
in the command stands for substitute, and the ^
and $
symbols stand for the beginning and end of the string respectively.
The following example will add double quotes around the string Hello World
:
echo "Hello World" | sed 's/^/"/; s/$/"/'
The output of this command is:
"Hello World"
If you want to use single quotes instead of double quotes, you can use the following command:
echo "Hello World" | sed "s/^/'/; s/$/'/"
The output of this command is:
'Hello World'
onelinerhub: How can I use the 'sed' command line utility to add quotes around a string?