From 4d1dc0bfe4890fe9fdb2eb8bcbc7f5272144f205 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 5 Mar 2021 19:04:52 -0600 Subject: [PATCH] Add Apply Multiple Substitutions To The Input as a sed til --- README.md | 3 ++- ...ply-multiple-substitutions-to-the-input.md | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 sed/apply-multiple-substitutions-to-the-input.md diff --git a/README.md b/README.md index 6183f62..6582189 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1071 TILs and counting..._ +_1072 TILs and counting..._ --- @@ -929,6 +929,7 @@ _1071 TILs and counting..._ ### sed +- [Apply Multiple Substitutions To The Input](sed/apply-multiple-substitutions-to-the-input.md) - [Extract Value From Command Output With Sed](sed/extract-value-from-command-output-with-sed.md) - [Use An Alternative Delimiter In A Substitution](sed/use-an-alternative-delimiter-in-a-substitution.md) diff --git a/sed/apply-multiple-substitutions-to-the-input.md b/sed/apply-multiple-substitutions-to-the-input.md new file mode 100644 index 0000000..f1dd948 --- /dev/null +++ b/sed/apply-multiple-substitutions-to-the-input.md @@ -0,0 +1,23 @@ +# Apply Multiple Substitutions To The Input + +You can apply multiple substitutions to the input of a `sed` command a couple +ways. + +One of those ways is to use the `-e` flag multiple times to define +substitutions that should be _appended_ to the `sed` script. + +```bash +$ echo 123 | sed -e 's/3/three/' -e 's/1/one/' +one2three +``` + +Another way is to define a single string as the `sed` script and separate each +substitution with a `;` (semicolon). + +```bash +$ echo 123 | sed 's/3/three/; s/1/one/' +one2three +``` + +Each of these will run each substitution in the `sed` script sequentially for +each line in the input.