sed, a stream editor
Table of Contents
Running sed
input.txthello
world
Following lines are equivalent to above:
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
-i
- in-place
-n
- suppress all lines
'45p'
- print line45
Following lines are all equivalent:
sed 's/hello/world/' input.txt > output.txt
sed -e 's/hello/world/' input.txt > output.txt
sed --expression='s/hello/world/' input.txt > output.txt
echo 's/hello/world/' > myscript.sed
sed -f myscript.sed input.txt > output.txt
sed --file=myscript.sed input.txt > output.txt
Command-Line Options
See /sed/cli
sed
scripts
- See /sed/scripts
<e sed
commands follow this syntax:
[addr]X[options]
- Commands within a script or script-file can be separated by semicolons (
;
)
30, 35
is[addr]
, which means lines from30
to35
.d
is thedelete
command
/^foo/
is a regular expression address.q
is thequit
command42
is the command option (exit code)
See /sed/commands