cli-sedHow do I delete a file using the command line sed tool?
To delete a file using the command line sed tool, you can use the following command:
sed -i '' '/<pattern>/d' <filename>
This command will delete all lines from the file that match the given <pattern>
.
The command consists of the following parts:
sed
- the command line sed tool-i ''
- an option that specifies that the given file should be edited in place/<pattern>/d
- a regular expression that specifies what lines should be deleted<filename>
- the name of the file to be edited
For example, if you want to delete all lines containing the word "hello" from the file example.txt
, you can use the following command:
sed -i '' '/hello/d' example.txt
This command will delete all lines containing the word "hello" from the file example.txt
.
Helpful 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 SED in a Windows command line interface?
- How do I use the CLI to configure Zabbix?
- How can I set up the Xcode command line interface?
- How do I use sed to add quotes around a string in a command line interface?
- How can I use sed in a CLI for Kubernetes?
- How can I use the 'sed' command line utility to group text?
- How can I use sed in a command line interface?
- How can I use cli sed to configure credentials?
- How can I use the 'sed' command line utility to add quotes around a string?
See more codes...