From 0348a644de6d6907e8e5b136dc68027a759898db Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Thu, 20 Aug 2015 16:59:41 +0100 Subject: [PATCH 1/3] various fixes and tweaks to sed - don't use g in all examples - fix option for extended regex (-E is in grep :)) - spell out the -i option and remove a stray `''` from that command - use the term "expressions" in the example using -e --- pages/common/sed.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pages/common/sed.md b/pages/common/sed.md index 87c4d0b4f..6e07a388d 100644 --- a/pages/common/sed.md +++ b/pages/common/sed.md @@ -2,21 +2,21 @@ > Run replacements based on regular expressions -- replace all occurrences of a string in a file, and print the result +- replace the first occurrence of a string in a file, and print the result -`sed 's/{{find}}/{{replace}}/g' {{filename}}` +`sed 's/{{find}}/{{replace}}/' {{filename}}` -- replace all occurrences of a string in a file, and overwrite the file +- replace all occurrences of a string in a file, overwriting the file contents -`sed -i '' 's/{{find}}/{{replace}}/g' {{filename}}` +`sed --in-place 's/{{find}}/{{replace}}/g' {{filename}}` - replace all occurrences of an extended regular expression in a file -`sed -E 's/{{regex}}/{{replace}}/g' {{filename}}` +`sed -r 's/{{regex}}/{{replace}}/g' {{filename}}` -- replace all occurrences of multiple strings in a file +- apply multiple find-replace expressions to a file -`sed -e 's/{{find}}/{{replace}}/g' -e 's/{{find}}/{{replace}}/g' {{filename}}` +`sed -e 's/{{find}}/{{replace}}/' -e 's/{{find}}/{{replace}}/' {{filename}}` From a92aec7dc09f9c6e2eeb3d0d9bc3bd9db4f65b8b Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Tue, 25 Aug 2015 00:56:09 +0100 Subject: [PATCH 2/3] restore short option -i per discussion in #293 --- pages/common/sed.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pages/common/sed.md b/pages/common/sed.md index 6e07a388d..14bc91de0 100644 --- a/pages/common/sed.md +++ b/pages/common/sed.md @@ -6,10 +6,9 @@ `sed 's/{{find}}/{{replace}}/' {{filename}}` -- replace all occurrences of a string in a file, overwriting the file - contents +- replace all occurrences of a string in a file, overwriting the file (i.e. in-place) -`sed --in-place 's/{{find}}/{{replace}}/g' {{filename}}` +`sed -i 's/{{find}}/{{replace}}/g' {{filename}}` - replace all occurrences of an extended regular expression in a file From 4a52a7006d20516b9f232af136212e2b58240cbd Mon Sep 17 00:00:00 2001 From: Ruben Vereecken Date: Thu, 21 Jan 2016 13:02:00 +0100 Subject: [PATCH 3/3] Formatted sed page --- pages/common/sed.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/common/sed.md b/pages/common/sed.md index 009e91e7d..b4054c9a7 100644 --- a/pages/common/sed.md +++ b/pages/common/sed.md @@ -2,11 +2,11 @@ > Run replacements based on regular expressions. -- replace the first occurrence of a string in a file, and print the result +- Replace the first occurrence of a string in a file, and print the result: `sed 's/{{find}}/{{replace}}/' {{filename}}` -- replace all occurrences of a string in a file, overwriting the file (i.e. in-place) +- Replace all occurrences of a string in a file, overwriting the file (i.e. in-place): `sed -i 's/{{find}}/{{replace}}/g' {{filename}}` @@ -14,6 +14,6 @@ `sed -r 's/{{regex}}/{{replace}}/g' {{filename}}` -- apply multiple find-replace expressions to a file +- Apply multiple find-replace expressions to a file: `sed -e 's/{{find}}/{{replace}}/' -e 's/{{find}}/{{replace}}/' {{filename}}`