From b2210a9ca212cdba15d2b97c7d97d02496d0f404 Mon Sep 17 00:00:00 2001 From: alexberry Date: Sun, 2 Feb 2020 10:29:36 +0000 Subject: [PATCH 1/3] Adding a few more useful examples. Sed's cheat sheet was a little light, here are a few more examples. --- sheets/sed | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sheets/sed b/sheets/sed index 3ebd5a4..2dc5b11 100644 --- a/sheets/sed +++ b/sheets/sed @@ -1,2 +1,14 @@ -# Edit a file, via substitution, in-place; changes are made to the file(s). +# Preview a file edit, via substitution. +sudo sed 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop + +# Replace the same string more than once (appending g flag), via substitution. +sudo sed 's/Name=Xfce Session/Name=Xfce_Session/g' /usr/share/xsessions/xfce.desktop + +# Edit a file (adding -i flag), via substitution, in-place; changes are made to the file(s). sudo sed -i 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop + +# It can become necessary to escape special characters in your string. +sed -i 's/\/path\/to\/somewhere\//\/path\/to\/anotherplace\//' + +# Change your sed delimiter to a pipe to avoid escaping slashes. +sed -i 's|/path/to/somewhere/|/path/to/anotherplace/|' From b2ef20e0d9615ccd5adef7e4286292c20fc729ea Mon Sep 17 00:00:00 2001 From: alexberry Date: Sun, 2 Feb 2020 10:32:28 +0000 Subject: [PATCH 2/3] Forgot to add paths as utilised -i Must add a file path when not piping to sed. --- sheets/sed | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sheets/sed b/sheets/sed index 2dc5b11..a10aa27 100644 --- a/sheets/sed +++ b/sheets/sed @@ -8,7 +8,7 @@ sudo sed 's/Name=Xfce Session/Name=Xfce_Session/g' /usr/share/xsessions/xfce.des sudo sed -i 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop # It can become necessary to escape special characters in your string. -sed -i 's/\/path\/to\/somewhere\//\/path\/to\/anotherplace\//' +sed -i 's/\/path\/to\/somewhere\//\/path\/to\/anotherplace\//' /tmp/filetoedit # Change your sed delimiter to a pipe to avoid escaping slashes. -sed -i 's|/path/to/somewhere/|/path/to/anotherplace/|' +sed -i 's|/path/to/somewhere/|/path/to/anotherplace/|' /tmp/filetoedit From 3f48743deeb207e440689796ddad68216c6e622a Mon Sep 17 00:00:00 2001 From: alexberry Date: Sun, 2 Feb 2020 10:45:33 +0000 Subject: [PATCH 3/3] g flag is per-line, not per-file Make comment clearer --- sheets/sed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheets/sed b/sheets/sed index a10aa27..34040a6 100644 --- a/sheets/sed +++ b/sheets/sed @@ -1,7 +1,7 @@ # Preview a file edit, via substitution. sudo sed 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop -# Replace the same string more than once (appending g flag), via substitution. +# Replace the same string more than once per line (appending g flag), via substitution. sudo sed 's/Name=Xfce Session/Name=Xfce_Session/g' /usr/share/xsessions/xfce.desktop # Edit a file (adding -i flag), via substitution, in-place; changes are made to the file(s).