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.txtCommand-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, 35is[addr], which means lines from30to35.dis thedeletecommand
/^foo/is a regular expression address.qis thequitcommand42is the command option (exit code)
See /sed/commands