Introduction
This article introduces articles using the sed command.
By executing the commands listed in each article one line at a time, you can verify their behavior on Ubuntu, macOS, and Windows, so please take a look if you’re interested.
What is the sed command?
The sed command is used to perform operations on input strings.
Strings are read from files or standard input.
Feature List
This article explains the following features:
- Delete
- Replace
- Extract
- Add
- Write
How do I delete a string using the sed command?
The second line of the input string can be deleted by writing it in the following format.
If you’d like to quickly check the functionality using a file, please refer to the article below.
- Delete specific lines in a file
- Delete rows within the specified range.
- Delete the last line in the file.
How do I replace a string using the sed command?
The following format will replace the first occurrence of “aaa” in the input string with “bbb”.
If you’d like to quickly check the functionality using a file, please refer to the article below.
- Replace trailing newlines.
- Replace the nth arbitrary string in each line.
- Replace a given string with a specified character.
How do I extract a string using the sed command?
The second line of the input string can be extracted by writing it in the following format.
If you’d like to quickly check the functionality using a file, please refer to the article below.
- Display a specific line in the file
- Display rows within the specified range.
- Display the last line in the file.
How do I add a string using the sed command?
The second line will be added as ddd by writing it in the following format.
If you’d like to quickly check the functionality using a file, please refer to the article below.
- Add a string to the beginning of the specified line.
- Add a string to the line following the specified line.
How do I write to a file using the sed command?
The following format will write ddd to the second line of test1.txt.
Ubuntu、Windows
macOS
If you’d like to quickly check the functionality using a file, please refer to the article below.