How to Use the sed Command on Linux for Text Editing
HardReset.InfoJanuary 1, 20269 min19 views
2 connectionsΒ·4 entities in this videoβUnderstanding the sed Command
- π‘ sed is a powerful stream editor on Linux used for searching, replacing, and modifying text directly from the terminal without opening a full editor.
- βοΈ The basic syntax involves
sed [options] 'command' filename, wherecommandspecifies the action to perform.
Basic Substitution and Global Replacement
- π― The
s/old/new/command is used for substituting text, replacing the first occurrence of 'old' with 'new' on each line. - π To replace all occurrences of a pattern on a line, use the global flag:
s/old/new/g. - β οΈ By default, sed only shows changes in the output; the original file remains unchanged.
In-Place Editing and Backups
- πΎ The
-ioption allows for in-place editing, modifying the file directly. - π To create a backup of the original file before editing, use
-i.bak, which appends.bakto the original filename.
Targeting Specific Lines and Deleting Lines
- π You can apply commands to specific lines by prefixing the command with the line number (e.g.,
6s/old/new/). - βοΈ A line range can be specified using a comma between line numbers (e.g.,
2,3s/old/new/) to apply changes to multiple lines. - ποΈ The
dcommand is used to delete specific lines from the file, and-iis needed to make this deletion permanent.
Knowledge graph4 entities Β· 2 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
4 entities
Chapters3 moments
Key Moments
Transcript32 segments
Full Transcript
Topics11 themes
Whatβs Discussed
sed commandLinuxStream EditorText EditingCommand LineSubstitutionGlobal ReplacementIn-place EditingFile BackupsLine TargetingDelete Lines
Smart Objects4 Β· 2 links
ConceptsΒ· 3
ProductΒ· 1