cli-sedHow can I use the 'sed' command line utility to add quotes around a string?
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'
Helpful links
More of Cli Sed
- How do I use the CLI to configure Zabbix?
- How can I use SED in a Windows command line interface?
- How can I use the command line tool sed to create a tutorial?
- How can I use sed in a command line interface?
- How can I use the sed command in the Ubuntu command line interface?
- How can I use the command line to edit text using Qt?
- How can I use sed command line options to modify text files?
- How can I grant permission to use the CLI sed command?
- How can I use a variable with the sed command line tool?
See more codes...