aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-18 00:12:48 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-18 00:13:11 +0100
commitd66fdbe1963ad9561a336ec95e476e41381a2d91 (patch)
treec12d4b5a805d3d9e6196e2cc59fb7caec0919c89 /src
parent1d5addd14bc3f0c7279b41882fc9b8ff60fac450 (diff)
downloadnotes-d66fdbe1963ad9561a336ec95e476e41381a2d91.tar.gz
notes-d66fdbe1963ad9561a336ec95e476e41381a2d91.zip
sed: add initial examples
Diffstat (limited to 'src')
-rw-r--r--src/SUMMARY.md1
-rw-r--r--src/tools/README.md1
-rw-r--r--src/tools/sed.md68
3 files changed, 70 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md
index d802912..0073de0 100644
--- a/src/SUMMARY.md
+++ b/src/SUMMARY.md
@@ -20,6 +20,7 @@
- [ffmpeg](./tools/ffmpeg.md)
- [column](./tools/column.md)
- [sort](./tools/sort.md)
+ - [sed](./tools/sed.md)
- [Resource analysis & monitor](./monitor/README.md)
- [lsof](./monitor/lsof.md)
diff --git a/src/tools/README.md b/src/tools/README.md
index 2aa2f5c..7b9b184 100644
--- a/src/tools/README.md
+++ b/src/tools/README.md
@@ -17,3 +17,4 @@
- [ffmpeg](./ffmpeg.md)
- [column](./column.md)
- [sort](./sort.md)
+- [sed](./sed.md)
diff --git a/src/tools/sed.md b/src/tools/sed.md
new file mode 100644
index 0000000..1746c24
--- /dev/null
+++ b/src/tools/sed.md
@@ -0,0 +1,68 @@
+# sed(1)
+
+```
+sed [opts] [script] [file]
+ opts:
+ -i edit file in place
+ -i.bk edit file in place and create backup file
+ (with .bk suffix, can be specified differently)
+ -e SCRIPT add SCRIPT to commands to be executed
+ (can be specified multiple times)
+ -f FILE add content of FILE to command to be executed
+
+ --debug annotate program execution
+```
+
+## Examples
+### Delete lines
+```sh
+# Delete two lines.
+echo -e 'aa\nbb\ncc\ndd' | sed '1d;3d'
+# bb
+# dd
+
+# Delete last ($) line.
+echo -e 'aa\nbb\ncc\ndd' | sed '$d'
+# aa
+# bb
+# cc
+
+# Delete range of lines.
+echo -e 'aa\nbb\ncc\ndd' | sed '1,3d'
+# dd
+```
+
+### Insert lines
+```sh
+# Insert before line.
+echo -e 'aa\nbb' | sed '2iABC'
+# aa
+# ABC
+# bb
+
+# Insert after line.
+echo -e 'aa\nbb' | sed '2aABC'
+# aa
+# bb
+# ABC
+
+# Replace line.
+echo -e 'aa\nbb' | sed '2cABC'
+# aa
+# ABC
+```
+
+### Substitute lines
+```sh
+# Substitute by regex.
+echo -e 'aafooaa\ncc' | sed 's/foo/MOOSE/'
+# aaMOOSEaa
+# cc
+```
+
+### Multiple scripts
+```sh
+echo -e 'foo\nbar' | sed -e 's/foo/FOO/' -e 's/FOO/BAR/'
+# BAR
+# bar
+```