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 command line to compress a file using SED and ZIP?
- How can I use sed in a command line interface?
- How do I use the CLI to configure Zabbix?
- How can I use the command line to compress and edit files with sed and zip?
- How can I use SED in a Windows command line interface?
- How do I use sed to insert a new line in a command line interface?
- How can I use sed in the command line on macOS?
- How do I use the command line to edit text using sed?
- How can I use CLI sed and Yarn together to develop software?
See more codes...