Text and processing
The sed command
Edits text as a stream: above all, replaces words inside lines.
Syntax
sed 's/antiguo/nuevo/[g]' [archivo]Most useful options
s/x/y/Replaces the first x of each lines/x/y/gReplaces allNdDeletes line NCopy-ready examples
$ echo hola mundo | sed 's/mundo/linux/'Replace a word$ echo aaa | sed 's/a/A/g'All a's to A$ sed 2d Documentos/tareas.txtDeletes the second lineYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- Without /g it only changes the first match of each line.
FAQ
Does sed change the original file?
Not by default: it writes the result on screen. To save it, redirect to a file.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course