HomeTutorsContact
commandline
Sed Introduction
Konrad Kuśmierz
Konrad Kuśmierz
June 21, 2023
1 min

Table Of Contents

01
Step 1 — Running sed
02
Step 2 — Command-Line Options
Sed Introduction

Step 1 — Running sed

Normally sed is invoked like this:

sed SCRIPT INPUTFILE...

For example, to replace all occurrences of ‘hello’ to ‘world’ in the file input.txt:

sed 's/hello/world/' input.txt > output.txt

If you do not specify INPUTFILE, or if INPUTFILE is -, sed filters the contents of the standard input. The following commands are equivalent:

sed 's/hello/world/' input.txt > output.txt
sed 's/hello/world/' < input.txt > output.txt
cat input.txt | sed 's/hello/world/' - > output.txt

sed writes output to standard output. Use -i to edit files in-place instead of printing to standard output. See also the W and s///w commands for writing output to other files. The following command modifies file.txt and does not produce any output:

sed -i 's/hello/world/' file.txt

Step 2 — Command-Line Options


Tags

Share

Konrad Kuśmierz

Konrad Kuśmierz

Software Engineer

Founder

Expertise

devops
ai

Social Media

instagramtwitterwebsite

Related Posts

Awk Introduction
Awk Introduction
June 21, 2023
2 min