summaryrefslogtreecommitdiff
path: root/.cheat/cheat/sed
diff options
context:
space:
mode:
Diffstat (limited to '.cheat/cheat/sed')
-rw-r--r--.cheat/cheat/sed17
1 files changed, 17 insertions, 0 deletions
diff --git a/.cheat/cheat/sed b/.cheat/cheat/sed
new file mode 100644
index 0000000..e22c97a
--- /dev/null
+++ b/.cheat/cheat/sed
@@ -0,0 +1,17 @@
+# To replace all occurrences of "day" with "night" and write to stdout:
+sed 's/day/night/g' file.txt
+
+# To replace all occurrences of "day" with "night" within file.txt:
+sed -i 's/day/night/g' file.txt
+
+# To replace all occurrences of "day" with "night" on stdin:
+echo 'It is daytime' | sed 's/day/night/g'
+
+# To remove leading spaces
+sed -i -r 's/^\s+//g' file.txt
+
+# To remove empty lines and print results to stdout:
+sed '/^$/d' file.txt
+
+# To replace newlines in multiple lines
+sed ':a;N;$!ba;s/\n//g' file.txt