cli-sedHow do I use the command line to edit text using sed?
The sed
command is a powerful tool for editing text in the command line. It works by applying a set of instructions, called a script, to a text file or stream. The following example shows how to use sed
to replace all instances of the word "cat" with the word "dog" in a text file called example.txt
:
sed 's/cat/dog/g' example.txt
This command will output the contents of example.txt
, with all instances of "cat" replaced by "dog".
The sed
command is made up of several parts:
s
: This is the command to substitute a string for another./cat/
: This is the string to be replaced./dog/
: This is the string to replace it with.g
: This is an optional flag that tellssed
to replace all instances of the string, rather than just the first one.
In addition to substitution, sed
can be used to delete lines, insert text, and perform other types of text manipulation. For more information, see the following links:
More of Cli Sed
- How can I use the command line to compress and edit files with sed and zip?
- How can I use CLI sed to create a new VPC?
- How can I use the 'sed' command line utility to add quotes around a string?
- How can I use the command line to print the output of a sed command?
- How can I use sed in a command line interface?
- 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 'sed' command line utility to group text?
- How can I use a variable with the sed command line tool?
- How do I use the commandline sed tool to edit a file?
See more codes...