From c4fdf1c5f2c9ebedd0dedba4449c015f98aecda5 Mon Sep 17 00:00:00 2001 From: johannst Date: Wed, 17 Jan 2024 23:37:49 +0000 Subject: deploy: 7199cf6515f9545f345b37a402293fc13bbb5a47 --- tools/sed.html | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 tools/sed.html (limited to 'tools/sed.html') diff --git a/tools/sed.html b/tools/sed.html new file mode 100644 index 0000000..655cafd --- /dev/null +++ b/tools/sed.html @@ -0,0 +1,288 @@ + + + + + + sed - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

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

+
# 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

+
# 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

+
# Substitute by regex.
+echo -e 'aafooaa\ncc' | sed 's/foo/MOOSE/'
+# aaMOOSEaa
+# cc
+
+

Multiple scripts

+
echo -e 'foo\nbar' | sed -e 's/foo/FOO/' -e 's/FOO/BAR/'
+# BAR
+# bar
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + -- cgit v1.2.3