From 0348a644de6d6907e8e5b136dc68027a759898db Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Thu, 20 Aug 2015 16:59:41 +0100 Subject: [PATCH 1/2] 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 87c4d0b4fa..6e07a388d5 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/2] 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 6e07a388d5..14bc91de0b 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