sed
, and
Syntax
sed [options] 'command' file
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
-i |
() | |
Common |
-n |
, | |
Common |
-e |
command | |
Common |
-E |
|
Common | |
g |
() | |
Common |
Examples
old new
sed 's/old/new/g' file.txt
sed -i 's/localhost/127.0.0.1/g' config.yml
10 20
sed -n '10,20p' file.txt
( # )
sed '/^#/d' config.conf
sed -i '/^$/d' file.txt
| ()
sed 's|/usr/local|/opt|g' paths.txt
Tips
- macOS sed -i : sed -i '' 's/a/b/g' file
- & : sed 's/[0-9]*/(&)/'
- | # and more,
- : find. -name '*.txt' | xargs sed -i 's/foo/bar/g'